SQL DatabaseLesson 60Free preview
SQL Auto Increment
This lesson is part of SQL · All levels
Summary
AUTO_INCREMENT automatically increases the value of the column each time a new line is added, and is generally paired to the primary key column. This way you don't have to fill out the ID manually so you reduce the risk of a value collision. The newly created id value can be read by the LAST_INSERT_ID function.
Key points
- AUTO_INCREMENT automatically generates a sequential unique value for each new line.
- It is usually paired with a primary key of the type INT or BIGINT.
- The next value can be checked with SELECT.
- You can set the starting value, for example AUTO_INCREMENT = 1000.
- Only one column per table can have AUTO_INCREMENT.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.