Ad space (banner)
🗄️SQL Lessons
Lesson 37 / 50

Auto-Numbering with AUTOINCREMENT

This lesson covers auto-numbering rows with AUTOINCREMENT, so you never have to manage IDs manually. It's for anyone searching "SQL AUTOINCREMENT tutorial."

Declaring id INTEGER PRIMARY KEY AUTOINCREMENT makes the database automatically bump the ID by one every time a new row is added — a standard, everyday setting that saves you from managing IDs yourself.

The example inserts rows with INSERT INTO students (name) VALUES ('Alice');, passing only the name — watch how the database automatically assigns 1, 2, and so on, even though the ID column is never mentioned.

A common early mistake is trying to specify the ID yourself in the INSERT statement — once a column is set to auto-increment, you should generally leave it to the database and just list the column names you're actually providing. Assigning your own IDs by hand risks duplicates the moment two people insert data at the same time — letting the database manage it automatically eliminates that whole class of bug.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)