Вопрос

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