Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

User Role Membership - SQL Server

RSS
Modified on Fri, May 06, 2022, 7:39 AM by Administrator Categorized as Uncategorized
SELECT 
    Username = U.name
   ,Roles    = STRING_AGG(r.name, ',')

FROM 
    sys.database_role_members AS DRM  

    inner join sys.database_principals AS r  
        ON DRM.role_principal_id = r.principal_id  
        and r.type = 'R'

    inner join sys.database_principals AS U  
        ON DRM.member_principal_id = U.principal_id 

group by
    u.name

ORDER BY 
    u.name 

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2022, Patrick Jasinski.