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!

Trigger to delete record on parent & child tables

Status
Not open for further replies.

qazz

Programmer
Oct 6, 2002
13
PH
Greetings!

Is there a trigger way to delete a particular record on parent table and automatically delete related records on child table?

Thank you,

Qazz
 
Code:
CREATE TRIGGER mytrigger
  ON parent
  FOR DELETE
AS

DELETE child
FROM child c JOIN deleted d ON c.fk_col = d.pk_col

--James
 
It is better to set up cascading deletes as these are more efficient than triggers.
 
Thank you James & SQL Sister.

SQLSister is suggesting that "It is better to set up cascading deletes as these are more efficient than triggers."

How can i do that?

Thanks,

Qazz
 
Simplest way is in ENterprise Manger, go to the table design form. Select the manage relationships button. Set up a relationship to the other child table. Then you can select cascade update and delte on the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top