locked
How to get last inserted row primary key in SQLite? RRS feed

  • Question

  • User355485 posted

    database.insert() method always returns 1 How to get last inserted row primary key auto incremented Id?

    1)SELECT * from SQLITESEQUENCE ** not working 2)SELECT lastinsertrowid() from TableName ** not working

    how to solve this?

    Monday, June 25, 2018 11:48 AM

All replies

  • User2148 posted

    i think every sqlite table has a rowid column

    https://sqlite.org/autoinc.html

    Monday, June 25, 2018 12:19 PM
  • User35290 posted

    Insert should already give you the auto incremented primary key. But if it doesn't, you could use SELECT MAX(id)

    Monday, June 25, 2018 12:20 PM
  • User398771 posted

    @AlessandroCaliaro said: i think every sqlite table has a rowid column

    https://sqlite.org/autoinc.html

    You always share links, do you think they don't open and study them. those of you who understand can immediately provide solutions and directions on how the code path applies.

    Thursday, January 28, 2021 5:36 AM
  • User2148 posted

    @ycusoy said:

    @AlessandroCaliaro said: i think every sqlite table has a rowid column

    https://sqlite.org/autoinc.html

    You always share links, do you think they don't open and study them. those of you who understand can immediately provide solutions and directions on how the code path applies.

    If you don't want links, you can write your own solution so people can just cut and paste it into their project (but they will continue not to study and to learn)

    Thursday, January 28, 2021 7:35 AM
  • User398771 posted

    @AlessandroCaliaro said: If you don't want links, you can write your own solution so people can just cut and paste it into their project (but they will continue not to study and to learn) I don't think everyone is like that. tell them about how the solution works, reasons, possibilities. This will make the questioner get a bright spot instead of having to read the old or new post page ,,

    Thursday, January 28, 2021 2:19 PM