T-SQL: SUSER_SNAME vs SUSER_NAME?

前端 未结 2 1989
一整个雨季
一整个雨季 2021-01-17 07:15

The MSDN documentation says for SUSER_SNAME function:

Returns the login identification name from a user\'s security identification number (SID).

<
2条回答
  •  感情败类
    2021-01-17 07:57

    SUSER_NAME() will return the name associated with an sid that exists in sys.server_principals. The sid must exist in sys.server_principals.

    SUSER_SNAME() can do that but also can return the sid of a login if the login is a member of an active directory group

    So if you have [CONTOSO\MyGroup] in Active Directory and that group has one user [CONTOSO\MyUser]

    And you add that group to SQL Server: CREATE LOGIN [CONTOSO\MyGroup] FROM WINDOWS;

    SELECT SUSER_ID('CONTOSO\MyUser'), SUSER_SID('CONTOSO\MyUser')

    will give you NULL, CONTOSO\MyUser because CONTOSO\MyUser is not in sys.server_principals but is in A/D

提交回复
热议问题