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)
 Delete Trigger

Author  Topic 

umapathy
Starting Member

24 Posts

Posted - 2007-12-04 : 22:03:04
Hi folks

how to fire a trigger when i delete record from a table.
for example , i have a two tables
emp1,emp

emp1

empid department
x sales
y production

emp

empid] name age address

x john 25 AP
Y Peter 30 TN

in this above two table if i delete record from emp1 the trigger should fire and then it should delete a relevent record form the emp table.

how should i achieve this?
can any one help this.

umapathy

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-12-04 : 23:18:50
To do that you shouldn't use a trigger, use a FOREIGN KEY constraint with cascading delete. Here's the docs on cascading referential integrity constraints
http://msdn2.microsoft.com/en-us/library/ms186973.aspx

If you really want to use triggers (not recommended) then look up the CREATE TRIGGER statement.
Go to Top of Page

umapathy
Starting Member

24 Posts

Posted - 2007-12-05 : 00:44:03
Thanks
Go to Top of Page
   

- Advertisement -