Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
LMS56K
Starting Member
6 Posts |
Posted - 2002-01-30 : 08:00:01
|
| Hello All,How do I create the following SQL Server 2000 database trigger?I am creating a database management system that logs computer related faults. The trigger that I want to create is related with two tables, Actual Faults (Fault_ID, description etc..) and Fault History (which is auto updated when the user updates a record in the Actual Faults table)Problem: I want to create a trigger that when the administrator deletes a record from the Actual Faults table it will delete all related records from the Fault History table. Please can anyone help!Cheers LeeHow much do you know about yourself if you've never been in a fight? |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-30 : 08:12:41
|
| You could use an ON CASCADE DELETE foreign key between the 2 tables, that would delete the related history rows when the fault rows are deleted.If you need the trigger, the following should work or be damn close:CREATE TRIGGER ON [Actual Faults] FOR DELETE ASDELETE FH FROM deleted D INNER JOIN [Fault History] FH ON (D.Fault_ID=FH.Fault_ID)However this trigger will not work if you have a foreign key declared between the two tables. You'd have to remove the foreign key or create an INSTEAD OF trigger to handle it. |
 |
|
|
|
|
|