开发者

Getting the primary key back from a SQL insert with SQLite

开发者 https://www.devze.com 2022-12-28 20:51 出处:网络
I have a SQL table set that looks like this create table foo ( id int primary key asc, data datatype );

I have a SQL table set that looks like this

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 record set.

insert into table foo (data) values (s开发者_开发问答tuff);

But wait - to get Bar all patched up hunkydory I need the PK from Foo. I know this is a solved problem.

What's the solution?


try this

SELECT last_insert_rowid() 
0

精彩评论

暂无评论...
验证码 换一张
取 消