Thursday, April 18, 2024

AUTO_INCREMENT

MySQL supports a unique incrementing number for a single database column using the AUTO_INCREMENT definition when specified with CREATE TABLE statement. This is a common use for a Primary Key. This implementation has some similar traits with a database sequence that is found in other RDBMS products.

You can determine the last value used for an AUTO_INCREMENT column using the LAST_INSERT_ID() function.

MySQL supports different ways of starting and incrementing an AUTO_INCREMENT column using the auto_increment_increment and auto_increment_offset system variables.

Only one table column can be defined as an AUTO_INCREMENT column and this column must be part of the table Primary Key.

References