Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Current SQL Server Login

Status
Not open for further replies.

TomBarrand

Programmer
Aug 9, 2000
162
GB
I want to write a trigger that is used for insert,update an delete and then writes some data to a log table to record what has been changed.

I need to get the SQL Server user name that the request came from, how do I do this?

Connections are via ODBC using SQL Server logins.

Cheers
 
SYSTEM_USER works for me through windows authentication, but presumably will work for sql server logins too

HTH

From BOL:

A. Use SYSTEM_USER to return the current system username
This example declares a char variable, puts the current value of SYSTEM_USER into the variable, and then prints the variable.
Code:
DECLARE @sys_usr char(30)
SET @sys_usr = SYSTEM_USER
SELECT 'The current system user is: '+ @sys_usr
GO
 
Since the system_user is only good for windows or sql authantication, is there any workaround thru the update trigger to record the user name from a web-based UI login to a sql audit table?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top