mysql插入测试数据示例

在接口自测及联调阶段,需要伪造数据供测试使用,以如下简单程序示例循环插入数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
drop procedure if exists test_insert;
DELIMITER //
create procedure test_insert()
begin
declare i int;
set i = 1000;
while i<1050 do
insert into account(agencyID,userName,referrer,account,weixin,card,createTime,verification,status,payStatus,firstLoginStatus) values(i,concat("test",i),2002428,concat(18841000,i),concat("testweixin",i),1000,date(now()),1,3,1,1);
set i = i+1;
end while;
end //
DELIMITER ;
call test_insert();

注释:DELIMITER作用是告诉Mysql解释器,该段命令是否已经结束。默认情况下,delimiter是分号;mysql一遇到分号,就要自动执行,所以需要事先把delimiter换成其它符号,如//或$$,最后再重置为默认值。