How to insert values ​​into auto join column in MYSQL

I would like to insert values ​​into the mysql column of innodb table Auto_Increment .

I load some data from the old table into a new table with the identifier and save the existing values ​​from the old table, so I need to keep the existing Id values, but keep the Auto_Increment column for the new values.

In MS T-SQL, I start my insert script query with SET SET IDENTITY_INSERT MyTable ON and end the SET SET IDENTITY_INSERT MyTable OFF query.

How can I do the same in MySQL?

+9
mysql mysql-workbench auto-increment
source share
1 answer

Just do as usual:

 INSERT INTO my_table(auto_inc_field, other_field) VALUES(8547, 'some value'); 

If the values ​​come from another table, you can use:

 INSERT INTO my_table(auto_inc_field, other_field) SELECT auto_inc_field, other_field FROM other_table; 
+8
source share

All Articles