How to set column as AUTO_INCREMENT in MySQL
How to set a column as AUTO_INCREMENT in MySQL
Content writing is the process of writing, editing, and publishing content in a digital format. That content can include blog posts, video or podcast scripts, ebooks or whitepapers, press releases, product category descriptions, landing page or social media copy and more.
Aryan Kumar
28-Jul-2023To set a column as auto_increment in MySQL, you can use the
AUTO_INCREMENT
keyword when creating the table. The syntax is as follows:SQL
For example, the following SQL statement will create a table called
products
with a column calledid
that is auto_incremented:SQL
Once you have created the table, you can insert new rows into the table without specifying a value for the
id
column. MySQL will automatically increment the value of theid
column for each new row that you insert.Here are some additional things to keep in mind about auto_increment columns:
AUTO_INCREMENT
keyword can only be used with integer columns.AUTO_INCREMENT
column is 1.AUTO_INCREMENT
column will increment by 1 for each new row that you insert.AUTO_INCREMENT
column by using theALTER TABLE
statement.