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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger Trouble: INSTEAD OF DELETE

Author  Topic 

cupeet987
Starting Member

11 Posts

Posted - 2007-12-27 : 12:44:00
I couldn't find much around the web about my problem... I want to use a INSTEAD OF DELETE trigger to enforce referencial integrity: every time I erease a record from a table X, instead of going straight to X, the trigger would erease first the records from the other tables and then to table X.

But I can't seem to find the syntax to, inside a INSTEAD OF DELETE trigger, after I erease all dependent tables finally erease the original one.

If anyone could supply me with sobre juicy exemples using this trigger I would be the most thankful.

Thanks in advance for your valuable time.

nr
SQLTeam MVY

12543 Posts

Posted - 2007-12-27 : 12:46:26
create trigger tr on mytbl insstead of delete
as
delete secondtable where id in (select id from deleted)
delete thirdtable where id in (select id from deleted)

delete mytbl where id in (select id from deleted)
go


==========================================
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.
Go to Top of Page
   

- Advertisement -