Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check users in a security group in SQL Server

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, but I have no idea how to query for it or where I could see this information. I tried looking in the properties, but couldn't find anything. Any ideas?

like image 656
Anna Avatar asked Sep 11 '13 21:09

Anna


People also ask

How do I list users in a SQL Server group?

To find the list of users/members associated with a single windows group login, use xp_logininfo. This will list all the members associated with the grouplogin “DomainABC\GroupName”.

How can I see what users a user is logged into SQL Server?

SQL Server: Find Logins in SQL Server Answer: In SQL Server, there is a catalog view (ie: system view) called sys. sql_logins. You can run a query against this system view that returns all of the Logins that have been created in SQL Server as well as information about these Logins.

How do I get list of Logins and permissions in SQL Server?

SQL Server includes a very useful system function sys. fn_my_permissions to list all the permissions of a particular principal (user or login) and this system function will help you list all permissions of a principal on a specific database object (securable).


2 Answers

Checking yourself or the current user:

SELECT IS_MEMBER('[group or role]')

A result of 1 = yes,0 = no, and null = the group or role queried is not valid.

To get a list of the users, try xp_logininfo if extended procs are enabled and the group in question is a windows group :

EXEC master..xp_logininfo 
@acctname = '[group]',
@option = 'members'
like image 98
DeanG Avatar answered Oct 28 '22 07:10

DeanG


For a quick view of which groups / roles the current user is a member of;

select
      [principal_id]
    , [name]
    , [type_desc]
    , is_member(name) as [is_member]
from [sys].[database_principals]
where [type] in ('R','G')
order by [is_member] desc,[type],[name]
like image 38
Edward Comeau Avatar answered Oct 28 '22 07:10

Edward Comeau