Home >Database >Mysql Tutorial >How to Make a MySQL Column Auto-Increment After Table Creation?
Modifying Columns to Auto_Increment in MySQL
Attempting to automatically increment a primary key column after the initial table creation can result in a syntax error. To successfully alter a column to have the AUTO_INCREMENT property, the correct MySQL syntax is as follows:
ALTER TABLE table_name MODIFY COLUMN column_name INT auto_increment
In your specific case, to make the document_id column in the document table auto-increment, you would use the following SQL statement:
ALTER TABLE document MODIFY COLUMN document_id INT auto_increment
It's important to note that the syntax for modifying a column to be auto-increment may vary slightly depending on the version of MySQL you are using. Always refer to the official MySQL documentation for the most up-to-date syntax.
The above is the detailed content of How to Make a MySQL Column Auto-Increment After Table Creation?. For more information, please follow other related articles on the PHP Chinese website!