Question: Hello, I have did part of the code for tiger auditing, this is how I did Insert and Delete, now I am having trouble on
Hello, I have did part of the code for tiger auditing, this is how I did Insert and Delete, now I am having trouble on what to do for Update, here are instructions for it:
For the Update operation, it will contain 2 records in the audit table, one for the old values (Operation will have
DELETED) and one for the new values (Operation will have INSERTED).
create TRIGGER trgEmployee ON Employee AFTER Insert,Delete, update AS BEGIN IF EXISTS(SELECT 1 FROM inserted) BEGIN INSERT INTO dbo.EmployeeAudit ( empNumber, firstName, lastName, ssn, address, [state], zip, jobCode, dateOfBirth, certification, salary, DateTimeStamp, Operation ) SELECT empNumber, firstName, lastName, ssn, address, [state], zip, jobCode, dateOfBirth, certification, salary, getdate(), 'INSERT' FROM INSERTED END IF exists(SELECT 1 FROM deleted) BEGIN INSERT INTO dbo.EmployeeAudit ( empNumber, firstName, lastName, ssn, address, [state], zip, jobCode, dateOfBirth, certification, salary, DateTimeStamp, Operation ) SELECT empNumber, firstName, lastName, ssn, address, [state], zip, jobCode, dateOfBirth, certification, salary, getdate(), 'DELETE' FROM deleted END if UPDATE(???????????????????????????????????????????????????) END GO
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
