Last active
November 5, 2015 00:59
-
-
Save levelboy/374ea20b8f4fb1112454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
// Trebuie sa facem o procedura. Se pare ca in mysql nu poti folosi loop-uri direct intr-un script. Am pus mai jos un script template pentru o procedura | |
DROP PROCEDURE IF EXISTS insert_grades$$ | |
CREATE PROCEDURE insert_grades() | |
BEGIN | |
set @number_of_students = (select count(*) from StudentData); | |
set @number_of_courses = (select count(*) from Course); | |
set @current_course_id = 1; | |
course_loop: WHILE @current_course_id < @number_of_courses DO | |
set @current_student_id = 1; | |
student_loop: WHILE @current_student_id < @number_of_students DO | |
insert into Grade (IdCourse, IdStudent, Grade) values(@current_course_id, @current_student_id, ceil(rand() * 10)); | |
set @current_student_id = @current_student_id + 1; | |
END WHILE student_loop; | |
set @current_course_id = @current_course_id + 1; | |
END WHILE course_loop; | |
END$$ | |
DELIMITER ; | |
// --------------- Script pentru procedura ------------------- | |
DELIMITER $$ | |
DROP PROCEDURE IF EXISTS insert_grades$$ | |
CREATE PROCEDURE insert_grades() | |
BEGIN | |
// ------------ Write your loops here ------------- | |
END$$ | |
DELIMITER ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment