Alter a MySQL column to be AUTO_INCREMENT

C. Ross picture C. Ross · Jan 30, 2010 · Viewed 419k times · Source

I’m trying to modify a table to make its primary key column AUTO_INCREMENT after the fact. I have tried the following SQL, but got a syntax error notification.

ALTER TABLE document
ALTER COLUMN document_id AUTO_INCREMENT

Am I doing something wrong or is this not possible?

+--------------------+
| VERSION()          |
+--------------------+
| 5.0.75-0ubuntu10.2 |
+--------------------+

Answer

roman picture roman · Jan 30, 2010
ALTER TABLE document MODIFY COLUMN document_id INT auto_increment