mercredi 7 janvier 2015

Inserting data into 4 tables at the same time in SQLite. How?

My database has 1 table that has a 1 to many relationship with 3 other tables. The foreign key in the 3 other tables is the primary key from the "master" table.


So now when I commit to the database ideally I'd insert into the master table and then into the other three tables, but with the correct keys.


Why don't I just so that then?


Because the primary key in the master table is, in SQLite, a INTEGER PRIMARY KEY that isn't defined and so is an auto increment number. I've no idea what it will be when I insert into the table.


I know one way to do this is to insert my own primary key, but that means querying the table for the newest primary key first.


Is there a good way to do this?


Aucun commentaire:

Enregistrer un commentaire