delimiter ;;
CREATE PROCEDURE insertData(in sum INT)
BEGIN
DECLARE count INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
set count=0;
set i = rand() * 10000;
set @exesql = concat("insert into single_table(id,key1,key2,key3, key_part1, key_part2,key_part3, common_field) values ");
set @exedata = "";
set @SURNAME = 'abcdefghijkrqeyrqerpeqwreqwfqewrr';
set @NAME = 'abcdefghijkrqeyrqerpeqwreqwfqewrrfadsfopdasfmalsdfklasdfkldakslfadmsfadfasdfa';
while count<sum do
set @key1 = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @key3 = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @key_part1 = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @key_part2 = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @key_part3 = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @common_field = concat(substr(@surname,floor(rand()*length(@surname)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1), substr(@NAME,floor(rand()*length(@NAME)/3+1),1));
set @exedata = concat(@exedata, ",('", i, "','", @key1, "','", i+1,"','", @key3,"','", @key_part1,"','", @key_part2,"','", @key_part3,"','", @common_field, "')");
set count=count+1;
set i=i+1;
if i%1000=0
then
set @exedata = SUBSTRING(@exedata, 2);
set @exesql = concat("insert into single_table(id,key1,key2,key3, key_part1, key_part2,key_part3, common_field) values ", @exedata);
prepare stmt from @exesql;
execute stmt;
DEALLOCATE prepare stmt;
set @exedata = "";
end if;
end while;
if length(@exedata)>0
then
set @exedata = SUBSTRING(@exedata, 2);
set @exesql = concat("insert into single_table(id,key1,key2,key3, key_part1, key_part2,key_part3, common_field) values ", @exedata);
prepare stmt from @exesql;
execute stmt;
DEALLOCATE prepare stmt;
end if;
end;
delimiter ;