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
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