Mysql数据库批量添加数据

1.目的:

  用于向Mysql表中批量插入数据

2.过程:

   

3.语句

#删除已有存储过程
DROP PROCEDURE if exists insertdata;
#设定命令行出现//后再执行语句
delimiter //
#创建存储过程
CREATE PROCEDURE insertdata()
#设定开始事务
begin
#申明变量
declare yourid int;
set yourid = 2;
#循环执行
while yourid < 5000 do
  insert into t_car(VIN, LicensePlate, TerminalCode, DomainCode, CarGroupId, AddTime, UpdateTime, CarType, CarModelCode, CustomerCode, CarColor, CarImg, motorNum, Remark)
  values(yourid, '浙A00002', yourid, 'BYD', 0, '2017-03-14', '2017-03-14', 0, 1, '', '', '', '', ''); 
  set yourid=yourid+1;
end while;
end//
#重新设置分隔符为';'
delimiter ;
#执行存储过程
call insertdata();

posted @ 2017-05-09 22:09  一夜泪水催人醉  阅读(818)  评论(0编辑  收藏  举报