0

I need to know the ID of newly created record, but this record has unique field:

CREATE TABLE materials (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT,
    color_id INTEGER,
    count INTEGER);

CREATE TABLE colors (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT UNIQUE ON CONFLICT IGNORE);

I'm using simple TextBox, to set color, I want it to be inserted and then receive it's id. How can I do this?

  • _SELECT last_insert_rowid()_ You should provide your code that inserts the new record to get a more precise answer – Steve Sep 18 '17 at 11:39
  • take a look at https://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c-sharp – burkay Sep 18 '17 at 11:40

1 Answers1

-1

For example: INSERT INTO color(name) VALUES("blue one") SELECT SCOPE_IDENTITY()

You can keep result in variable and then use in another query. You can also use some ORM and it will handle for you.

Possible duplication of that one.

Bear
  • 1,017
  • 1
  • 10
  • 23