SQLite last insert rowid

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

SQLite last_insert_rowid() function

Description

The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function.

Note : The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function.

Syntax

last_insert_rowid()

Example : SQLite last_insert_rowid() function

sqlite> DELETE from table1;
sqlite> SELECT * FROM table1;
sqlite> INSERT INTO table1 VALUES(1, 'AAA');
  1. SELECT last_insert_rowid();  
last_insert_rowid()
-------------------
1
sqlite> INSERT INTO table1 VALUES(2, 'BBB');
  1. sqlite> SELECT last_insert_rowid();  
last_insert_rowid()
-------------------
2