如何在MYSQL的自动识别列中插入值 [英] How to insert values into auto identity column in MYSQL
问题描述
我想将值插入mysql innodb表Auto_Increment
列.
I would like to insert values into mysql innodb table Auto_Increment
column.
我正在将一些数据从旧表加载到具有标识的新表中,并且需要保留旧表中的现有值,因此我需要保留现有的Id
值,但要保留列
I am loading some data from an old table to new table which has an identity, and need to preserve the existing values from the old table, so I need to preserve the existing Id
values, but keep the column Auto_Increment
for new values.
在MS T-SQL中,我将以SET SET IDENTITY_INSERT MyTable ON
开始insert
查询脚本,并以SET SET IDENTITY_INSERT MyTable OFF
结束查询.
In MS T-SQL, I would start my insert
query script with SET SET IDENTITY_INSERT MyTable ON
and end the query with SET SET IDENTITY_INSERT MyTable OFF
.
如何在MySQL中做同样的事情?
How can I do the same in MySQL?
推荐答案
只需照常做:
INSERT INTO my_table(auto_inc_field, other_field) VALUES(8547, 'some value');
如果这些值来自另一个表,则可以使用:
If the values are comming from another table, you may use:
INSERT INTO my_table(auto_inc_field, other_field)
SELECT auto_inc_field, other_field FROM other_table;
这篇关于如何在MYSQL的自动识别列中插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!