dbTalk Databases Forums  

A Question on Triggers

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss A Question on Triggers in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dom
 
Posts: n/a

Default A Question on Triggers - 04-25-2011 , 10:38 AM






I'm just reading through the help sites for information about creating
a Trigger. I'm using it to debug a program. The trigger will record
the exact time a record is updated in a certain table. My question
is: Is there any way to capture the user that is doing the updating?
For example is there something like a GET_USER_ID() function that I
can record in the trigger?

Thanks, Dom

Reply With Quote
  #2  
Old   
Fred.
 
Posts: n/a

Default Re: A Question on Triggers - 04-25-2011 , 11:12 AM






On Apr 25, 11:38*am, Dom <dolivas... (AT) gmail (DOT) com> wrote:
Quote:
I'm just reading through the help sites for information about creating
a Trigger. *I'm using it to debug a program. *The trigger will record
the exact time a record is updated in a certain table. *My question
is: *Is there any way to capture the user that is doing the updating?
For example is there something like a GET_USER_ID() function that I
can record in the trigger?

Thanks, Dom
SYSTEM_USER is documented in as returning the login name of the
current user. What it seem to return in my environment is the login
ID of the current user, in the form [domain]\[userid] where [domain]
is the short or local domain name.

Fred.

Reply With Quote
  #3  
Old   
Dom
 
Posts: n/a

Default Re: A Question on Triggers - 04-25-2011 , 12:51 PM



On Apr 25, 12:12*pm, "Fred." <ghrno-goo... (AT) yahoo (DOT) com> wrote:
Quote:
On Apr 25, 11:38*am, Dom <dolivas... (AT) gmail (DOT) com> wrote:

I'm just reading through the help sites for information about creating
a Trigger. *I'm using it to debug a program. *The trigger will record
the exact time a record is updated in a certain table. *My question
is: *Is there any way to capture the user that is doing the updating?
For example is there something like a GET_USER_ID() function that I
can record in the trigger?

Thanks, Dom

SYSTEM_USER is documented in as returning the login name of the
current user. *What it seem to return in my environment is the login
ID of the current user, in the form [domain]\[userid] where [domain]
is the short or local domain name.

Fred.
Thanks, Fred. Exactly what I wanted.

Dom

Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: A Question on Triggers - 04-25-2011 , 01:42 PM



Fred. (ghrno-google (AT) yahoo (DOT) com) writes:
Quote:
SYSTEM_USER is documented in as returning the login name of the
current user. What it seem to return in my environment is the login
ID of the current user, in the form [domain]\[userid] where [domain]
is the short or local domain name.
Small caveat here: it is better in most cases to use original_login().

In most cases, they will show the same thing, but if there has been
impersonation, original_login() will show you the user who actually
logged into SQL Server.
--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.