Using Delphi 7 and interbase 7
Is it possible to delete a master detail record and all of its nested detail records in one SQL statement?
Example:
Table1
ID - Integer
TITLE - Varchar(80)
Table2
ID - Integer
Table1_ID - Integer
TITLE - Varchar(80)
Table3
ID - Integer
Table2_ID - Integer
TITLE - Varchar(80)
I would like to delete ID 10 from Table1, and all of its matching records (Table1_ID) in table 2, and all its matching records (Table2_ID) in table 3
If i can't do this in one sql, how do i do it in multiple sqls (correct sequence to call statements)?
Yo can do it witn some SQL's deleteing in order, records on Table3, table2 and table1. All in one transaction to do it like "unique operation".
One alternative is use Triggers for delete record related on table2 when you delete one record on table1, and equivalent in table2 to delete related records on table3.
Another (if DB let you) is use ON CASCADE DELETE (or similar) to delete related records on a tabla2 and table3, when you delete a record un table1 (see help or documentation on your SGBD/Database).
Excuse-me for mistakes with English. It's not my natural language.
Regards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With