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?
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 Dkrueger25 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.