How to add AUTO_INCREMENT to an existing column?

mpen picture mpen · Feb 18, 2011 · Viewed 134.4k times · Source

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

Answer

Don Kirkby picture Don Kirkby · Feb 18, 2011

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.