I've attached a database to my primary and then copied one record from the attached database to the new one.
INSERT INTO Recipes (
Recipetitle, Numberofservings, Recipeauthor, Categories, Subcategories,
Preparationtime, Cookingtime, Difficulty, Recipeversion, Recipesource,
Copyright, Cuisine, Reciperating, Importedfrom, Authorcomments,
Instructions, Nutritionaldata, Othercomments, Homepage, Deleted,
Updated, Favourite, Locked, Selected, Shopping)
Select
Recipetitle, Numberofservings, Recipeauthor, Categories, Subcategories,
Preparationtime, Cookingtime, Difficulty, Recipeversion, Recipesource,
Copyright, Cuisine, Reciperating, Importedfrom, Authorcomments,
Instructions, Nutritionaldata, Othercomments, Homepage, Deleted,
Updated, Favourite, Locked, Selected, Shopping
FROM RemoteDatabase.Recipes
WHERE Recordid = 1'
I've got the new record number from the above insert using "SELECT last_insert_rowid()" stored in a variable.
No problem so far.
My pictures table looks like this, linked to the recipes table by a foreign key:
CREATE TABLE IF NOT EXISTS Pictures(
Pictureid INTEGER PRIMARY KEY AUTOINCREMENT,
Picture BLOB,
Description TEXT,
FileName TEXT,
Recordid INTEGER,
FOREIGN KEY(Recordid) REFERENCES Recipes(Recordid) ON DELETE CASCADE)
How do I add the linked Recordid from the recipes table in the Insert Into in the below statement? Have tried a few things and come up with not enough columns or other mistakes.?
INSERT INTO Pictures (Picture, Description, FileName, Recordid)
SELECT
Picture, Description, FileName
FROM RemoteDatabase.Recipes
WHERE Recordid = 1
Aucun commentaire:
Enregistrer un commentaire