Technical Article

Cascade Delete

,

Having two tables Parent and Derived in ont-to-many relations we want to realize a cascade delete so that for a certain list of parent to delete all the coresponding items from Derived

I use a INSTEAD OF DELETE.

CREATE TRIGGER tgDelete
ON Parent INSTEAD OF DELETE
AS

DELETE Derived 
FROM   Derived, deleted   
WHERE  Derived.fkKey  = deleted.pkKey

DELETE Parent 
FROM   Parent , deleted   
WHERE  Parent.pkKey  = deleted.pkKey

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating