Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query to display user and all permissions associated?

Posted on 2012-04-09
2
Medium Priority
?
354 Views
Last Modified: 2012-04-17
Hello,

I am looking for a query that displays every user and his or hers associated permissions as well as associated server roles. Thank you in advance. . .
0
Comment
Question by:fstinc
2 Comments
 
LVL 7

Accepted Solution

by:
Anoo S Pillai earned 2000 total points
ID: 37826072
I believe you are looking for two queries :) , Please see the following queries, which will be useful to you.

-- Object level permissions
SELECT      Obj.name ,Perm.permission_name , Principal.Name
FROM      sys.database_permissions      Perm
JOIN      sys.database_principals      Principal
ON      Perm.grantee_principal_id = Principal.principal_id
JOIN      (SELECT DISTINCT(id) ObjID FROM sys.syspermissions WHERE id > 0) AS SysPerm
ON      SysPerm.ObjID = Perm.major_id
JOIN      sys.sysobjects Obj
ON      Obj.id = SysPerm.objid
WHERE      Perm.major_id = SysPerm.ObjID

-- Role member ship

SELECT      ROLE.[name] Role ,  Principal.[name] Principal
FROM      sys.database_role_members ROLEMEMBER
JOIN      sys.database_principals as ROLE
ON            ROLEMEMBER.role_principal_id = ROLE.principal_id
JOIN      sys.database_principals as PRINCIPAL
ON            ROLEMEMBER.member_principal_id = PRINCIPAL.principal_id

Hope this is helpful.
0
 

Author Comment

by:fstinc
ID: 37858318
Thank you!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question