Subject | RE: Deleting from linked tables |
---|---|
Author | Roger Vellacott |
Post date | 2001-10-05T08:24:49Z |
Try this
Assuming A.Key links to B.AKey, and B.Key links to C.BKey....
DELETE FROM A WHERE EXISTS
(SELECT * FROM C WHERE C.F1 = ACertainValue
AND C.BKey IN (SELECT KEY FROM B WHERE B.AKey = A.KEY));
Cascading deletes from A through B and C should be defined in the FKs or in
the relevant triggers.
Roger Vellacott
Robert Munro wrote
<I have 3 tables, A is the parent of B which is the parent of C. I >
<want to delete all the records related to a record in A if one of the >
<fields in C is a certain value. >
<It doesn't seem like an unlikely scenario. How can I do this? >
Assuming A.Key links to B.AKey, and B.Key links to C.BKey....
DELETE FROM A WHERE EXISTS
(SELECT * FROM C WHERE C.F1 = ACertainValue
AND C.BKey IN (SELECT KEY FROM B WHERE B.AKey = A.KEY));
Cascading deletes from A through B and C should be defined in the FKs or in
the relevant triggers.
Roger Vellacott
Robert Munro wrote
<I have 3 tables, A is the parent of B which is the parent of C. I >
<want to delete all the records related to a record in A if one of the >
<fields in C is a certain value. >
<It doesn't seem like an unlikely scenario. How can I do this? >