In SQLite I would like to delete parent table row and it has to delete all the related child tables. I have gone through all the questions in StackExchange and other websites but my query no where satisfied.
I have four tables.
TableA:
id, primary key
name
TableB:
id, primary key
issues,
tb_aid, #foreign key ref to TableA id
tb_cid, #foreign key ref to TableC id
tb_did, #foreign key ref to TableD id
tb_eid, #foreign key ref to TableE id
TableC:
id, primary key
column1,
tb_bid, #foreign key ref to TABLE B id
TableD:
id,
name
TableE
id,
name
I tried JOIN
but unfortunately its not working in SQLite. I dont know how to use TRIGGER
. Is it possible to use ON CASCADE DELETE
for the above case.
Best Answer
You can use on cascade delete
Example
Turn on FK Support
Create sample data
Delete the value from TableA
Select from tableB
Result
DB<>Fiddle
You do have bidirectional FK's in your example, while I do not think it is a good design, you could use something like the DB Fiddle below.
DB<>Fiddle