Check users in a security group in SQL Server

前端 未结 6 2072
情歌与酒
情歌与酒 2020-12-30 04:42

In the Security/Users folder in my database, I have a bunch of security groups, include \"MyApplication Users\". I need to check if I am (or another user is) in this group,

6条回答
  •  暖寄归人
    2020-12-30 05:20

    The code that is provided on the Microsoft page here works for me, every time.

    SELECT DP1.name AS DatabaseRoleName,   
       isnull (DP2.name, 'No members') AS DatabaseUserName   
     FROM sys.database_role_members AS DRM  
     RIGHT OUTER JOIN sys.database_principals AS DP1  
       ON DRM.role_principal_id = DP1.principal_id  
     LEFT OUTER JOIN sys.database_principals AS DP2  
       ON DRM.member_principal_id = DP2.principal_id  
    WHERE DP1.type = 'R'
    ORDER BY DP1.name;
    

    Please let me know if this works for you!

提交回复
热议问题