SQL Server - 当前用户名 [英] SQL Server - current user name

查看:35
本文介绍了SQL Server - 当前用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用哪个来记录用户所做的更新?

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

  1. SYSTEM_USER,或
  2. ORIGINAL_LOGIN(),或
  3. SUSER_SNAME()

推荐答案

SYSTEM_USER 返回当前正在执行的上下文,因此这可以返回模拟上下文

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

ORIGINAL_LOGIN() 返回最初连接到实例的用户的身份,因此无论上下文是否被模拟,它都会产生登录的原始用户,便于审计.

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() 如果您想通过 SID 获取用户名,则使用此方法,因此可以使用诸如 SUSER_SNAME([server_user_sid]) 但如果您不传递当前用户返回的参数,则 SID 是可选的.

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.

这篇关于SQL Server - 当前用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆