Home > Database > Mysql Tutorial > 修复mysql数据库自增字段的AUTO_INCREMENT起始值的存储过程_MySQL

修复mysql数据库自增字段的AUTO_INCREMENT起始值的存储过程_MySQL

WBOY
Release: 2016-06-01 13:09:46
Original
1269 people have browsed it

delimiter $$create procedure repair_auto_increment(IN db varchar(10))	begin	declare tmp_name char(30) default "";	declare tmp_cursor cursor for		select TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=db;	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET tmp_name = null;		open tmp_cursor;	fetch tmp_cursor into tmp_name;	while(tmp_name is not null)	do		set @sql = concat('alter table ', tmp_name);		set @sql = concat(@sql, ' auto_increment=1');		prepare stmt from @sql;		execute stmt;		fetch tmp_cursor into tmp_name;	end while;	close tmp_cursor;	end$$delimiter ;
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template