Let's say I have 3 tables in a hierarchy:
TableA -> TableB -> TableC
TableC
has a foreign key relationship with TableB
, and TableB
has a foreign key relationship with TableA
.
If i delete a record in TableA
, it should cascade delete down through the hierarchy. Using ON DELETE CASCADE
would work fine.
However let's say I need to put an INSTEAD OF
trigger on TableC
. My understanding is that an INSTEAD OF
trigger can not be put on a table that has a delete cascade going to it. Taken from MSDN:
For INSTEAD OF triggers, the DELETE option is not allowed on tables that have a referential relationship specifying a cascade action ON DELETE.
If I have to take the cascade delete off TableB->TableC
, I would need to use an INSTEAD OF
trigger to enforce Referential Integrity, and then I have the same problem with TableB->TableA
. This is a simple example, but imagine the cascade path being much larger. It seems like it could easily snowball throughout a long cascade path.
So what are the best practices for dealing with this scenario?