MySQL Tutorial
In MySQL, the AUTO_INCREMENT
attribute is used to automatically generate unique values for a column, typically for a primary key. It automatically increments the value by 1 for each new row inserted into the table.
PRIMARY KEY
or UNIQUE
constraint.INT
, BIGINT
, TINYINT
, etc.).CREATE TABLE table_name ( column_name INT AUTO_INCREMENT, other_column data_type, PRIMARY KEY (column_name) );
The following SQL statement defines the "student_id" column to be an auto-increment primary key field in the "Persons" table:
To let the AUTO_INCREMENT
sequence start with another value, use the following SQL statement: