mysql过程更新ID库中自增值

BEGIN


DECLARE strName VARCHAR(45);
DECLARE done INT DEFAULT FALSE;
declare table_names CURSOR for 
select table_name from information_schema.`TABLES` where table_schema='erp1000_id' and TABLE_NAME in (select table_name from information_schema.`TABLES` where table_schema='erp1000_dev8') ;
DECLARE CONTINUE HANDLER FOR NOT FOUND set done=true;


create temporary table if not exists temp_sql
(`remark` varchar(255) DEFAULT NULL
);


open table_names;
fetch table_names into strName;
while not done DO
set @sql1 = concat('SELECT max(id)+1 into @maxid from erp1000_dev8.',strName);
prepare stmt1 from @sql1;
EXECUTE stmt1;
-- SELECT @maxid;
deallocate prepare stmt1;






if @maxid is not null then
set @sql = concat('alter table erp1000_id.',strName ,' auto_increment= ',@maxid);
-- prepare stmt from @sql;
-- execute stmt;
-- deallocate PREPARE stmt;
insert into temp_sql SELECT @sql;
end if;


fetch table_names into strName;
end while;
close table_names;
SELECT * from temp_sql;
truncate TABLE temp_sql;
END
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值