SQLite 3 reference · Conditional and Type Functions

SQLite LAST_INSERT_ROWID() Function

Return the rowid of the most recent successful INSERT on this connection, such as a new auto-generated ID.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

last_insert_rowid()

Return value

An integer (0 if nothing has been inserted).

Examples

The new row's IDTry it yourself
INSERT INTO categories (name) VALUES ('Garden');
SELECT last_insert_rowid() AS new_id;

Output

new_id
5
RETURNING (3.35+) gives it directlyTry it yourself
INSERT INTO categories (name) VALUES ('Sports')
RETURNING category_id, name;

Output

category_id | name
5 | Sports

Was this page helpful?