Blog Index
How to add AUTO_INCREMENT to an existing column?
Oct. 28, 2021 | Categories:Method to add AUTO_INCREMENT to a table with data while avoiding “Duplicate entry” error: 1. Make a copy of the table with the data using INSERT SELECT: CREATE TABLE backupTable LIKE originalTable; INSERT backupTable SELECT * FROM originalTable; 2. Delete data from originalTable (to remove duplicate entries): TRUNCATE TABLE originalTable; 3. To add AUTO_INCREMENT and PRIMARY KEY ...