I want to know if I can repopulate the autoincrement value in mysql.
Because, I have records that look similar:
ID Name
1 POP
3 OLO
12 lku
Basically , I want a way to update the ID to this
ID Name
1 POP
2 OLO
3 lku
Is there any way to do this in mysql?
Thanks.
It’s not best practice to fiddle your primary keys – better to let your DB handle it itself. There can be issues if, in between the
UPDATEandALTER, another record is added. Because of this, you mustLOCKthe table, which might hang other queries and spike load on a busy production server.OR – for thousands of rows (with no foriegn key dependencies):
The latter method will only work where you have no foreign keys. If you do, you’ll require a lookup table.
You now have a
lookuptable with the old to new ids which you can use to update the foreign key dependencies on your other tables (on a test server!)