문제

I got two tables, one of which is a helper of the other. The table "reviews" has a column which is an integer referencing to the id of the film of that review in the table "films". Is there a way to, after inserting in the table "films" a new film, use the last_insert_rowid in the table "reviews"?

I'm using SQLITE; I've seen uses with max(id) but it might not be as reliable. Help would be greatly appreciated.

도움이 되었습니까?

해결책

You can just simply use it as a value in your next insert, à la

INSERT INTO films (name) values ('Shark!');
INSERT INTO reviews (filmId,review) values (last_insert_rowid(), 'Good!');

Demo here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top