Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cascade delete trigger

Status
Not open for further replies.

richey1

Technical User
Oct 5, 2004
184
GB
I have 3 tables tblEnquiry, tblExempt, tblAppeal

tblEnquiry is the parent with primary key EnquiryID

tblExempt/tblAppeal have foreign keys set-up to EnquiryID

I now can't delete a record on tblEnquiry where a record exist in one of the other tables. fine ?(i hope) so can i create a trigger that says if the record is deleted in tblEnquiry it cascades down to the other two ?

any help appreciated
thanks
kim

i tried something like

CREATE TRIGGER tg_cascadedelete ON [dbo].[tblEnquiry]
AFTER DELETE
AS
DELETE FROM tblExempt WHERE EnquiryID = tblEnquiry.EnquiryID
 
If that's all you want to do why not specify the cascading delete in the foreign key definitions?

Code:
CONSTRAINT FK_name FOREIGN KEY REFERENCES tblEnquiry(EnquiryID) ON DELETE CASCADE

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top