如何在mySQL数据库的表中插入100000条记录.
我的想法是:
BEGIN
declare i=0,n=100000;
while (i<n) DO
i++;
insert into tableName values (1,2,3);
END while;
END
Run Code Online (Sandbox Code Playgroud)
我需要的原因:如果这些记录在数据库中,则测试服务器上的负载.
有没有简单的一行查询可以解决这个问题?
从表中插入回自身:
insert into tableName values (1,2,3);
insert into tableName select * from tableName; -- 2 rows
insert into tableName select t.* from tableName t, tableName t2, tableName t3, tableName t4; -- raised to 4th power every execution
insert into tableName select t.* from tableName t, tableName t2, tableName t3, tableName t4; -- raised to 4th power every execution
Run Code Online (Sandbox Code Playgroud)
现在有104994行
请参见SQLFiddle
您可以在一个命令中将表的多个副本添加到交叉连接中,以增加数量的增加功率.