使用old_table_name的AUTO_INCREMENT值创建TABLE new_table_name之类的old_table_name [英] CREATE TABLE new_table_name LIKE old_table_name with old_table_name's AUTO_INCREMENT values
问题描述
我可以在mysql客户端中创建具有旧表的自动导入状态的新表吗?
Can I create a new table with an old table's autoincriment status in mysql client?
我认为ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment
可以帮助我,但是此构造必须使用恒定值.
我不想使用困难的脚本.
I think, that ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment
helps me, but this construction must use with a constant value.
I don't want to use a difficult script.
推荐答案
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;
谢谢我的兄弟!
这篇关于使用old_table_name的AUTO_INCREMENT值创建TABLE new_table_name之类的old_table_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!