Transforming a MySQL Column into AUTO_INCREMENT
Modifying an existing MySQL column to become AUTO_INCREMENT
is done using the ALTER TABLE
command. The example SQL provided earlier has a syntax error. Here's the correct approach:
<code class="language-sql">ALTER TABLE document MODIFY COLUMN document_id INT AUTO_INCREMENT;</code>
Let's dissect this command:
ALTER TABLE document
: This targets the table named "document" for modification.MODIFY COLUMN document_id
: This specifies the column, "document_id", to be changed.INT AUTO_INCREMENT
: This sets the data type to integer (INT
) and enables automatic incrementing for new rows.After executing this statement, the document_id
column will be an AUTO_INCREMENT
column, typically also functioning as the primary key.
The above is the detailed content of How Do I Make a MySQL Column AUTO_INCREMENT?. For more information, please follow other related articles on the PHP Chinese website!