SQL Auto Increment

Auto-increment allows a unique number to be generated automatically when a new record is inserted. This is commonly used for primary keys — ensuring each record gets a unique identifier without manual input.

Tutorials dojo strip

SQL Auto Increment Syntax

In SQLite, you declare a column as INTEGER PRIMARY KEY AUTOINCREMENT. In our playground, AUTOINCREMENT works only with the column declared as INTEGER PRIMARY KEY.

SQL

SQL Auto Increment Syntax for MySQL

SQL

Note: This syntax does not work in SQLiteAUTO_INCREMENT is specific to MySQL.

SQL Auto Increment Syntax for SQL Server

SQL
  • IDENTITY(1,1) means: start at 1 and increment by 1.

Note: IDENTITY is not valid in SQLite.

SQL Auto Increment Syntax for Access

SQL

Note: AUTOINCREMENT is specific to Microsoft Access and not supported in SQLite.

SQL Auto Increment Syntax for Oracle

In Oracle, auto-increment is achieved using a SEQUENCE:

SQL

Then use the sequence when inserting:

SQL

Note: Oracle sequences are not supported in SQLite.

SQL Auto Increment Example

This query creates a table using SQLite’s auto-increment format:

SQL

To insert a new patient:

SQL

This query will insert Maria Santos and assign a unique id automatically.

You can confirm with:

SQL

SQL Auto Increment Labs

Tutorials dojo strip