Tuesday, February 9, 2010

SQL Server – Get current user

Today I needed to know the current user while executing a trigger to write some audit data.

Getting the current user is very easy using following statement:


SYSTEM_USER will return the  name of the currently executing context. If the EXECUTE AS statement has been used to switch context, SYSTEM_USER returns the name of the impersonated context.

No comments: