1

Is there a smart way of getting the primary key that is auto incremented rather than rowID while inserting in the database, basically i don't want to write a new query to get the primary key of the last entry, is there any way to get the primary key using its rowID.

Thanks in advance.

Zubair Akber
  • 2,760
  • 13
  • 30
  • This question does not make sense; in SQLite, [the autoincremented key always is the rowid](http://stackoverflow.com/questions/3695224/sqlite-getting-nearest-locations-with-latitude-and-longitude). – CL. Nov 03 '15 at 08:03

1 Answers1

1

Option 1 : If you use The Android SQLite DB class methods, they return the last inserted id.

Option 2 : SELECT last_insert_rowid();

Refer to question

Community
  • 1
  • 1
Varun Verma
  • 542
  • 4
  • 17
  • does this return me the primary key i have settled in the table ? – Zubair Akber Nov 03 '15 at 06:52
  • @ZubairAkber - I suppose you have autoincrement on your primary key .. In that case it returns the last inserted row id ... – Varun Verma Nov 03 '15 at 06:55
  • Thanks for your answer but i want to get the primary key instead of rowID or is there a way to get row data by its rowID – Zubair Akber Nov 03 '15 at 07:12
  • @ZubairAkber - Then please explain what is your primary key ? Share the create SQL code of your table. If your primary key is NOT the auto increment integer, then it means that you are manually inserting a primary key ... If you are manually inserting - then you already have ... – Varun Verma Nov 03 '15 at 07:16