开发者

SQL Server - current user name

开发者 https://www.devze.com 2023-01-23 08:45 出处:网络
Which one should I use to record update made by users? SYSTEM_USER, or ORIGI开发者_运维技巧NAL_LOGIN(), or

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

  1. SYSTEM_USER, or
  2. ORIGI开发者_运维技巧NAL_LOGIN(), or
  3. SUSER_SNAME()


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号