Austin Ziegler wrote:

On 8/3/05, Khamis Abuelkomboz <[EMAIL PROTECTED]> wrote:

I'm using SQLite in my application and am very excited about this little
and fast database.

How can I retrieve the last created autoincrement value?
On MySQL and SQLServer or just the SQL standard I can fire the following
select statement:

Actually, as far as I know, SELECT @@IDENTITY isn't part of any ANSI
SQL standard. It cerrtainly won't work on Oracle ;)

That said, you can get the identity value of an autoincremented key
with sqlite3_last_insert_rowid
( It's
something of a cheat, but it works and works very well.

In SQLite you can also do the same thing directly from SQL if you want. There is a corresponding SQL function called last_insert_rowid(). So you can use;

select last_insert_rowid();

This will return the rowid of the last inserted row, which is the key for a table with an integer primary key (SQLite's version of autoincrement keys). It can also be used to get the rowid for tables with other kinds of keys or even no user specified key.

Dennis Cote

Reply via email to