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
 Transact-SQL (2000)
 CreatedBy and ModifiedBy

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2005-07-22 : 03:09:05
Hi everyone

I'm creating fields on one of my table to track who is modified and created the records.

I'm thinking to use trigger as I did for DateModified field. But I am not sure how you can get the login database that who's trying modify that table. Is there any SQL in-built function for this?

Any help regarding I'm really appreciated that.

Thanks



emilg
Starting Member

13 Posts

Posted - 2005-07-22 : 03:54:03
You can use the function USER_NAME().

For reducing overhead instead of a FOR INSERT trigger you can use USER or CURRENT_USER with DEFAULT constraints (see BOL).

CREATE TABLE inventory2
(
part_id int IDENTITY(100, 1) NOT NULL,
description varchar(30) NOT NULL,
entry_person varchar(30) NOT NULL DEFAULT USER
)
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-07-22 : 04:44:43
use system_user instead to get the actual login used.

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -