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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cascading Delete (trigger?) 1

Status
Not open for further replies.

Affleck

Technical User
Jun 19, 2001
26
GB
Hi again evrybody, im back with another simple question (hopefully)

How do I create a trigger so that when a record is deleted from a parent table all related child records are deleted also?

Ive done this in the past by enforcing Ref Integrity in Access but im using MS Sql now.

Thanks in advance. ;-)
 
Hiya

It is quite simple, you just need to create a trigger to do this:

CREATE TRIGGER (name) ON (table) FOR DELETE AS

DELETE query(s)



There is a table called 'deleted' which contains the rows that have been deleted from the main table, which you can reference to cascade your deletes down. It is the same structure as the MAIN table you have deleted rows from.

HTH

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top