Creating a SQL Server trigger to capture data
How can I create a SQL Server trigger that captures the user name and system date in fields within a record after any field in that record has been updated?

Software/Hardware used:
ASKED: February 2, 2009  6:06 PM
UPDATED: February 2, 2009  6:50 PM

Answer Wiki:
I have asked a similar question in the past and Mrdenny was able to assist me with the information below: That trigger would look something like this. CREATE TRIGGER t_YourTable_u on dbo.YourTable FOR UPDATE AS UPDATE YourTable SET UserName = suser_sname(), DateChanged = getdate() FROM inserted WHERE inserted.PK_Column = YourTable.PK_Column Table and column names will need to be changed to match your table and column names. The table inserted is a virtual table who's name can not be changed. This worked great for me.
Last Wiki Answer Submitted:  February 2, 2009  6:50 pm  by  Dkrueger   25 pts.
All Answer Wiki Contributors:  Dkrueger   25 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _