A表結構
create table user_fans(
`id` int(11) unsigned not null auto_increment,
`user_id` int(11) not null,
`fans_id` int(11) not null,
primary key (`id`)
);
B表結構
create table user_fans123(
`id` int(11) unsigned not null auto_increment,
`user_id` int(11) not null,
`fans_id` int(11) not null,
primary key (`id`)
);
復制表數據從A到B
insert into user_fans123 select * from user_fans;
這里有一份使用存儲過程批量生成數據來做演示
create procedure user_fans_procedure(out count int)
begin
declare i int;
set i = 1;
add_loop:loop
set i = i+1;
if i > 50 then
leave add_loop;
else
insert into user_fans (`user_id`,`fans_id`) values (i,I+1);
end if;
set count = i;
end loop add_loop;
select count;
end;
call user_fans_procedure(@count);
本文摘自 :https://blog.51cto.com/k