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
Syntax
last_insert_rowid()
Return value
An integer (0 if nothing has been inserted).
Examples
INSERT INTO categories (name) VALUES ('Garden');
SELECT last_insert_rowid() AS new_id;
Output
new_id 5
INSERT INTO categories (name) VALUES ('Sports')
RETURNING category_id, name;
Output
category_id | name 5 | Sports
Related
CHANGES()· Return how many rows the most recent INSERT, UPDATE or DELETE changed. total_changes() counts since the connection opened.- SQL INSERT · tutorial