w3resource

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');
SELECT last_insert_rowid();

Sample Output:

last_insert_rowid()
-------------------
1
sqlite> INSERT INTO table1 VALUES(2, 'BBB');
sqlite> SELECT last_insert_rowid();

Sample Output:

last_insert_rowid()
-------------------
2

Previous: hex()
Next: length()



Follow us on Facebook and Twitter for latest update.