sql 批量插入数据 存储过程

a) 先把下面的语句执行一遍,然后生成了一个test的函数(这个名字随你改)

注意:小明后面的那个i 是自动增长的,从小明1开始一直到小明10000,i可以用在其他列中,你自己调用。

begin

declare i int;

set i=1;

while i<=10000 do

INSERT INTO `org`.`sys_user` (`did`, `username`,`jobnumber`, `sex`, `email`, `phone`, `password`, `status`, `remark`) VALUES('1', concat('小明',i), '10017', '男', '[email protected]', '13569848512','123456', '1', NULL);

set i=i+1;

end while;

看图可能更加清楚关键字:

sql 批量插入数据 存储过程_第1张图片

b) 调用存储过程

CALL test(); 

c) 恭喜你插入了一万条数据

你可能感兴趣的:(数据库)