参考:http://vicky001.blog.51cto.com/2004660/384808
DELIMITER $$ #设置结束语句为$$
CREATE PROCEDURE INSERT_STUDENTS(IN scount INT,IN gcount INT,IN ccount INT,IN stucount INT)
BEGIN
DECLARE s INT;
DECLARE g INT;
DECLARE c INT;
DECLARE stu INT;
DECLARE sid INT;
DECLARE gid INT;
DECLARE cid INT;
DECLARE stuid INT;
SET s = scount;
WHILE s> 0 DO
INSERT INTO school VALUES (NULL ,CONCAT('school',s),'shool others');
SET sid = LAST_INSERT_ID();
SET g = gcount;
WHILE g > 0 DO
INSERT INTO grade VALUES(NULL ,sid ,CONCAT('grade' , g));
SET gid = LAST_INSERT_ID();
SET c =ccount;
WHILE c > 0 DO
INSERT INTO class VALUES(NULL,gid,CONCAT('class' ,c));
SET cid = LAST_INSERT_ID();
SET stu = stucount;
WHILE stu > 0 DO
INSERT INTO student VALUES(NULL,cid,CONCAT('student',stu),5);
SET stu = stu - 1;
END WHILE;
SET c = c -1 ;
END WHILE;
SET g = g - 1;
END WHILE ;
SET s = s - 1;
END WHILE;
COMMIT;
END $$
DELIMITER ;
CALL(2,4,100,100);