Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select last identity for table in SQLite?

Tags:

sqlite

I'm looking for the equivalent of Scope_identity() or @@identity in sql server, except for sqllite?

I'd hate to resort to a max select on the id column, but that is plausible.

like image 737
DevelopingChris Avatar asked Mar 27 '11 21:03

DevelopingChris


2 Answers

Since I have never used SQL Server, I am not exactly sure what @@IDENTITY does, but if I understand this document correctly, then sqlite3_last_insert_rowid() may be what you are looking for.

like image 123
thkala Avatar answered Sep 19 '22 14:09

thkala


last_insert_rowid()

This function returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function.

Reference

like image 41
Durai Amuthan.H Avatar answered Sep 16 '22 14:09

Durai Amuthan.H