Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL can I insert specific ids into an auto-increment column

Tags:

mysql

I accidentally deleted some rows in my database, but I have a copy of the data in a backup.

Is it possible to insert the rows back in with the same id (auto-increment field). Or do I have to use the auto-increment generated id then update all the relationships manually?

like image 211
wobbily_col Avatar asked Feb 05 '14 10:02

wobbily_col


1 Answers

You can, just by setting the field when INSERTing. Autoincrement only works if no value is specified for the field.

like image 128
Leonid Shevtsov Avatar answered Nov 06 '22 22:11

Leonid Shevtsov