66

Which one should I use to record update made by users?

  1. SYSTEM_USER, or
  2. ORIGINAL_LOGIN(), or
  3. SUSER_SNAME()
0

2 Answers 2

113

SYSTEM_USER returns the current executing context, so this can return an impersonated context

ORIGINAL_LOGIN() returns the identity of the user that initially connected to the instance, so regardless whether the context is impersonated or not it will yield the original user that logged in, good for auditing.

SUSER_SNAME() this is used if you want to get the username by SID so SUSER_SNAME can be invoked with a parameter like such SUSER_SNAME([server_user_sid]) but the SID is optional if you don’t pass that parameter the current user is returned.

1
  • 3
    Can SUSER_SNAME() return an impersonated context?
    – fordareh
    Sep 25, 2012 at 18:13
0

The current user (including during impersonation) can be found with SELECT USER_NAME()

https://learn.microsoft.com/en-us/sql/t-sql/functions/user-name-transact-sql?view=sql-server-ver16

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.