How to set a column as AUTO_INCREMENT in MySQL
How to set column as AUTO_INCREMENT in MySQL
491
27-Jul-2023
Aryan Kumar
28-Jul-2023To set a column as auto_increment in MySQL, you can use the
AUTO_INCREMENTkeyword when creating the table. The syntax is as follows:SQL
For example, the following SQL statement will create a table called
productswith a column calledidthat is auto_incremented:SQL
Once you have created the table, you can insert new rows into the table without specifying a value for the
idcolumn. MySQL will automatically increment the value of theidcolumn for each new row that you insert.Here are some additional things to keep in mind about auto_increment columns:
AUTO_INCREMENTkeyword can only be used with integer columns.AUTO_INCREMENTcolumn is 1.AUTO_INCREMENTcolumn will increment by 1 for each new row that you insert.AUTO_INCREMENTcolumn by using theALTER TABLEstatement.