gpt4 book ai didi

mysql - CREATE TABLE new_table_name LIKE old_table_name with old_table_name's AUTO_INCREMENT 值

转载 作者:行者123 更新时间:2023-11-29 01:15:16 24 4
gpt4 key购买 nike

我可以在 mysql 客户端中使用旧表的自动增量状态创建新表吗?

我认为 ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment 对我有帮助,但此构造必须使用常量值。我不想使用困难的脚本。

最佳答案

mysql> 像 old_table 一样创建表 new_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> 从@query准备stmt;

mysql> 执行stmt;

mysql> deallocate prepare stmt;

谢谢我的兄弟!

关于mysql - CREATE TABLE new_table_name LIKE old_table_name with old_table_name's AUTO_INCREMENT 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2361982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com