I want to make a trigger in ms sql server which saves every insert,update or delete had been made in my database and which user made the change.Something like a log file or exactly a log file.
What i’ve made so far is this:
CREATE TRIGGER Log_Creators_Modifiers ON Quotation
FOR INSERT,UPDATE AS
DECLARE
@ChangeType NVARCHAR
BEGIN
/* 'created' for an INSERT, 'Delete' for DELETE, and 'modified' for UPDATE. */
IF INSERT()
BEGIN
SET @ChangeType ='CREATED';
END
ELSE IF UPDATE()
BEGIN
SET @ChangeType = 'MODIFIED';
END
ELSE IF DELETE()
BEGIN
SET @ChangeType = 'DELETE';
END
END
Any help pls?
Not hugely easy but as ever someone has got there beofre you and save you the work
Audit triggers
does that help at all
or maybe this one where the nice man has even done the script dynamically to add the audit to all the tables
More triggers
I wouldn’t write this myself – just copy what’s already there