3

mysql クライアントで古いテーブルの自動インクリメント ステータスを使用して新しいテーブルを作成できますか?

それは私を助けると思いますALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_imentが、この構造は定数値で使用する必要があります。難しいスクリプトは使いたくない。

4

2 に答える 2

9

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;

お兄ちゃんにthx!

于 2010-03-02T11:00:52.760 に答える
0

CREATE TABLE では、使用する auto_increment を指定できます。

mysql> create table foo (i int primary key auto_increment, s varchar(12)) auto_increment = 10;
Query OK, 0 rows affected (0.19 sec)

mysql> insert into foo (s) values ("s");
Query OK, 1 row affected (0.09 sec)

mysql> select * from foo;
+----+------+
| i  | s    |
+----+------+
| 10 | s    |
+----+------+
1 row in set (0.03 sec)
于 2010-03-02T09:31:47.307 に答える