MySQL存储过程循环插入数据

平时测试,由于我们的测试数据量不够,不能很好的测试sql性能,故写了一个sql存储过程脚本,可以轻松写入100W+数据。

delimiter //                                        ——   与结尾的【end//】共同构成一个结构体,告诉mysql,以下命令是一个整体,否则mysql会遇到【;】就执行
CREATE PROCEDURE insertdata()           ——  创建一个名为insertdata的存储过程
begin
declare yourid int;   ——  声明 yourid变量为int型
declare tid int;                                    
declare types int;
declare id int;
set yourid = 270;   ——  为 yourid变量赋值
set tid = 270 ;                             
set types = FLOOR(1 + RAND() * (4));      ——  为 types变量赋值,值为1~4的随机值
set id = 43200; 
while yourid<5270 do          ——设定循环条件(双循环)
set yourid=yourid+1; 

while tid <350  do              ——设定循环条件
set types = FLOOR(1 + RAND() * (4));      
insert into wp_logs VALUES ( id,64,tid,yourid,types,1474360037,1,0,'');    —— 执行insert 语句
set tid=tid+1;      ——  为 tid变量赋值
set id=id+1;    
END WHILE;


set tid = 270 ;                                                    
END WHILE;
end //


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章