· 9 years ago · Oct 19, 2016, 04:52 AM
1create table aList
2( listId int not null,
3 studentId int not null,
4 unique key (listId,studentId)
5);
6
7drop procedure if exists createARandomList;
8DELIMITER $$
9create procedure createARandomList
10( listId int, -- groups them by a list number
11 nHowMany int, -- how many numbers to you want
12 nMaxNum int -- max of any one number
13)
14BEGIN
15 DECLARE i int;
16
17 set i=1;
18 WHILE i<nHowMany DO
19 INSERT IGNORE aList(listId,studentId) VALUES (listId,floor(rand()*nMaxNum)+1);
20 set i=i+1;
21 END WHILE;
22END
23$$
24DELIMITER ;