Trigger question in MS SQL 2005 on update /insert audit
Posted on 2007-11-28
I have created this trigger below to audit updates and inserts to my table, I also want any updates or inserts to be copied to another table called labdata, and then logged in my audit table. how would i do this?
this is what i have so far and it works for what i have so far.
CREATE TRIGGER AuditSamples
ON dbo.[Samples Received]
AFTER INSERT, UPDATE
--NOT FOR REPLICATION
DECLARE @Operation char(6)
IF EXISTS(SELECT * FROM deleted)
SET @Operation = 'Update'
SET @Operation ='Insert'
INSERT INTO dbo.SamplesAudit(DateChanged,TableName,UserName,Operation)
SELECT GetDate(),'[Samples Received]', suser_sname(),
--End of Trigger