Getting primary key from SQL insert using SQLite

I have a set of SQL tables that looks like

create table foo ( 
    id int primary key asc, 
    data datatype );

create table bar ( 
    id int primary key asc, 
    fk_foo int,
    foreign key(foo_int) references foo(id));

Now I want to insert a recordset.

insert into table foo (data) values (stuff);

But wait, to get Bar, all fixed hunkydory I need a PC from Foo. I know this is a problem.

What's the solution?

+3
source share
1 answer

try it

SELECT last_insert_rowid() 
+9
source

Source: https://habr.com/ru/post/1743930/


All Articles