Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all expertsPls hepl me how to write a triggers which records who (username) just update or insert the certain table in data. I have to do that because there some users use eachown user login to Server. And I want to record all of information about those users.Thank so much. Nice working day.daquoc
Kristen
Test
22859 Posts
Posted - 2005-09-06 : 02:12:44
"Hi all experts"That rules me out!Something like this perhaps?
CREATE TRIGGER dbo.MyTriggerON dbo.MyTableAFTER INSERT, UPDATEASSET NOCOUNT ON UPDATE U SET [ChangedDate] = GetDate(), [ChangedUser] = user_name() FROM inserted I JOIN dbo.MyTable U ON U.MyPKColumn = I.MyPKColumnGO