Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 04/09/2012 :  05:40:00  Show Profile  Reply with Quote
hi to all,
I need a trigger that deletes records from a table when they are deleted from another table.
The records to be deleted were inserted into user table by copying the table where I want to control lines erased.
In summary:
I have a table of detailed records and when a registration is deleted need to be deleted the same record in another table that contains the same records but summarized.
Already grateful.

Mike Teixeira

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 04/09/2012 :  07:38:24  Show Profile  Reply with Quote
You can create a trigger on the detailed records table. In the trigger code, you will have access to the rows that were deleted via the DELETED virtual table. You can examine that table and decide how to update/delete rows from the summary table.

One thing to keep in mind is that the DELETED virtual table can have more than one row. This comes about because the trigger gets called once for each delete operation regardless of the number of rows affected by the delete action.
Go to Top of Page


5072 Posts

Posted - 04/09/2012 :  11:40:53  Show Profile  Visit russell's Homepage  Reply with Quote
I've said it a million times and I'll say it again: this is a bad idea!

It is far better to use stored procedures to to all of the deletes.

Triggers that delete data and cascading keys cause unexpected data loss and difficult to track down bugs.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000