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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Tracking username

Author  Topic 

daquoc
Starting Member

35 Posts

Posted - 2005-09-06 : 00:27:46

Hi all experts
Pls 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.MyTrigger
ON dbo.MyTable
AFTER INSERT, UPDATE
AS
SET NOCOUNT ON

UPDATE U
SET
[ChangedDate] = GetDate(),
[ChangedUser] = user_name()
FROM inserted I
JOIN dbo.MyTable U
ON U.MyPKColumn = I.MyPKColumn
GO

Kristen
Go to Top of Page

daquoc
Starting Member

35 Posts

Posted - 2005-09-07 : 05:24:06
Thank so much
daquoc
Go to Top of Page
   

- Advertisement -