Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have two table 1.Employee_Test 2. Employee_Test_Audit i create trigger like below but when i delete record from table one (Employee_Test) then second table(Employee_Test_Audit) data was not deleted ...... :p
SQL
ALTER TRIGGER Trigger1_Delete
ON dbo.Employee_Test
FOR   DELETE
AS
    declare @empid numeric(18, 0);	
	
    select @empid=i.Emp_ID from inserted i;		
	
   DELETE FROM Employee_Test_Audit where Emp_ID=@empid
Posted
Updated 30-Nov-13 3:04am
v2

1 solution

The reason that nothing is being deleted from the Employee_Test_Audit is because @empid is null. You are querying the virtual INSERTED table whilst in a DELETE trigger... change
SQL
select @empid=i.Emp_ID from inserted i;
to
SQL
select @empid=i.EmpID from deleted i;
 
Share this answer
 
Comments
dhiraj mane 2-Dec-13 1:22am    
Thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900