Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Create or alter trigger tr_emp_after_allDML_operation

ON Employee_info
AFTER insert, delete, update
AS
BEGIN
---- insert
if exists (select * from inserted) And NOt exists(select * from deleted)
INSERT INTO employeelog
select EmpID, EmpName, EmpSalary, job, Phone, DeptID, 'arvind', GETDATE()
from deleted ;

-- update
else if exists (select * from inserted) And exists(select * from
deleted)
INSERT INTO employeelog
select EmpID, EmpName, EmpSalary, job, Phone, DeptID, 'arvind', GETDATE()
from inserted ;
--deleted
else if exists (select * from deleted) And not exists(select * from
inserted)
INSERT INTO employeelog
select EmpID, EmpName, EmpSalary, job, Phone, DeptID, 'arvind', GETDATE()
from deleted ;

else
begin
print 'nothing change ....'
return
end;
End;

You might also like