arachide
arachide

Reputation: 8066

how to get rowid when insert a row to table

I hope to add a row to a table in a sqlite database.

[NSString stringWithFormat:@"INSERT INTO myTable (rowid,myName ) VALUES (NULL, '%@');" , [aInfo myString]];

rowid is auto increment.

After insert the row, I hope to get the rowid that generate by sqlite automatically.

Is it possible?

welcome any comment

Thanks

Upvotes: 3

Views: 1351

Answers (2)

Sheetal Inani
Sheetal Inani

Reputation: 128

you can use select max(rowid) from myTable

Upvotes: 0

caligari
caligari

Reputation: 2128

You can get the new generated id with the last_insert_rowid() function. See http://www.sqlite.org/c3ref/last_insert_rowid.html

You do not say what language are you using, but search in your SQLite library implementation for last_insert_rowid function...

Upvotes: 5

Related Questions