use test;
drop table if exists t;
create table t (id int not null,name varchar(30));
#创建存储过程,输入记录数,插入t表行数据
delimiter $$
create procedure proc1(cnt int)
begin
declare i int default 1;
start transaction;
repeat
insert into test.t (id,name) values (i,concat('a',i));
set i = i + 1;
until i > cnt end repeat;
commit;
end$$
delimiter ;
#调用存储过程proc1,1百万条记录
call proc1(1000000);
#查看记录数
select count(*) from t;
#查看执行时间
select * from t where id=1500;
#t表id列建立索引
create index idx_id on t(id);
show keys from t;
#查看执行时间
select * from t where id=1500;
用存储过程向表中插入100万条数据
最新推荐文章于 2024-03-22 11:08:25 发布