MySQL DatabaseLesson 60Free preview
MySQL Auto Increment
This lesson is part of MySQL · All levels
Summary
AUTO_INCREMENT automatically adds a column of value every time a new line is inserted, so you don't have to fill in the ID manually. These columns are usually paired with a primary key of the type INT or BIGINT. The next value is usually taken from the largest value ever used so it is not reused.
Key points
- AUTO_INCREMENT can only be used in one column per table and must be indexed (e.g. PRIMARY KEY)
- When INSERT does not mention this column, the value is filled automatically
- The initial value can be set with the AUTO_INCREMENT = n option when CREATE TABLE
- The value used once is not recalculated even if the last line is deleted
- AUTO_INCREMENT applies to numerical types such as INT and BIGINT
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.