CREATE TABLE new_table_name LIKE old_table_name,带有old_table_name的AUTO_INCREMENT值

Min*_*nor 2 mysql create-table auto-increment sql-like

我可以在mysql客户端中创建一个具有旧表自动注册状态的新表吗?

我认为,这ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment有助于我,但这种结构必须使用恒定的价值.我不想使用困难的脚本.

Min*_*nor 7

MySQL的> create table new_table like old_table;

MySQL的> select @my_auto_increment:=auto_increment from information_schema.tables where table_name='old_table';

MySQL的> set @query = CONCAT("alter table new_table auto_increment = ", @my_auto_increment);

MySQL的> prepare stmt from @query;

MySQL的> execute stmt;

MySQL的> deallocate prepare stmt;

感谢我的兄弟!