MySQL存储过程例子收集

 


 

将大表循环多次插入多个表

在此基础上就可以实现分表了,比如将一个3000万的表切割为10张表

 

create procedure cuttable()
begin
 
declare i int;
declare start_var int;
 
set i=0;
 
while i<=300 do
 
    set start_var = (i-1)*10000;
    insert into timo_subscribe_001 select * from timo_subscribe order by id ASC limit start_var, 10000;
    set i=i+1;
 
end while;
 
end

 

待加入