使用存储过程生成测试数据

作者:じ☆ve宝贝

发布时间:2017-06-06T10:55:57

存储过程:


DELIMITER $$

DROP PROCEDURE IF EXISTS `school`$$

CREATE PROCEDURE `school`()
BEGIN
DECLARE v_cnt DECIMAL (10)  DEFAULT 0 ;
DECLARE id DECIMAL (10)  DEFAULT 0 ;
dd:LOOP 
          INSERT  INTO user_school VALUES 
		(NULL,id+1,'清华'),
		(NULL,id+2,'北大'),
		(NULL,id+3,'北航'),
		(NULL,id+4,'北电'),
		(NULL,id+5,'北邮'),
		(NULL,id+6,'华南理工'),
		(NULL,id+7,'花呗理工'),
		(NULL,id+8,'浙大'),
		(NULL,id+9,'汉大帮'),
		(NULL,id+10,'秘书帮')
			;
                  COMMIT;
                    SET v_cnt = v_cnt+10 ;
                           IF  v_cnt = 10000 THEN LEAVE dd;
                          END IF;
         SET id = id+10;
         END LOOP dd ;
END$$

DELIMITER ;

注意 IF v_cnt = 10000(插入条数,此处为10000条) THEN LEAVE dd;

执行存储过程:call school