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 |
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2004-01-09 : 07:52:08
|
| I need to Create a trigger that will delete the records in a sub table When the record in the master table is deleted. But I need to be sure it only works when the entire record in the master Table is deleted not just a field or two. Will this work ???CREATE TRIGGER "SpecOrder_DelrecTrigger"ON dbo.SpecOrderFOR DELETE AS DELETE FROM dbo.SpecOrderdetailFrom DeletedWHERE (dbo.SpecOrderdetail.SpecorderID = Deleted.SpecorderID) JimUsers <> Logic |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-01-09 : 07:57:10
|
| You might considerDELETE FROM dbo.SpecOrderdetailFrom dbo.SpecOrderdetailjoin Deletedon dbo.SpecOrderdetail.SpecorderID = Deleted.SpecorderIDNote that if there is a foreign key involved then thye error will occur before the trigger is fired. In this case you will need an instead of trigger and include the delete from the master table in the trigger.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2004-01-09 : 10:13:37
|
| Thanks NigelJimUsers <> Logic |
 |
|
|
|
|
|