Search code examples
mysqlauto-increment

How to add AUTO_INCREMENT to an existing column?


How do I add auto_increment to an existing column of a MySQL table?


Solution

  • I think you want to MODIFY the column as described for the ALTER TABLE command. It might be something like this:

    ALTER TABLE users MODIFY id INTEGER NOT NULL AUTO_INCREMENT;
    

    Before running above ensure that id column has a Primary index.