Tsallaka zuwa abun ciki
Justice Tech School

Auto Increment

Auto increment gives each new row the next number. The keyword differs: AUTOINCREMENT (SQLite), AUTO_INCREMENT (MySQL), SERIAL or GENERATED ... AS IDENTITY (PostgreSQL) and IDENTITY (SQL Server). In SQLite an INTEGER PRIMARY KEY already does it.

Example
CREATE TABLE tickets (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  subject TEXT
);
INSERT INTO tickets (subject) VALUES ('Login problem'), ('Refund request');
SELECT * FROM tickets;

Result

id | subject
1  | Login problem
2  | Refund request

Exercise

Which keyword generates ids in MySQL?

id INT  PRIMARY KEY

Quiz Test

Why use auto increment?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.