lundi 30 mars 2015

SQLite - How to delete parent row and keep the child/children rows?

I understand the concepts of PRAGMA foreign_key and of ON DELETE RESTRICT/NO ACTION, but I am facing kind of a different situation.


I need to delete a parent row but keep the child row associated with it. For example:



CREATE TABLE A(id, name);
INSERT INTO A(id, name) VALUES (1, "Loreum");

CREATE TABLE B(id, id_A, name) FOREIGN KEY(id_A) REFERENCES A(id);
INSERT INTO B(id, id_A, name) VALUES (1, 1, "Opium");
DELETE FROM A WHERE id = 1;


I want to achieve this while keeping the child row intact. Is this possible at all?


Aucun commentaire:

Enregistrer un commentaire