如何在MYSQL的自动识别列中插入值 [英] How to insert values into auto identity column in MYSQL

查看:78
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆