1-- SQL Server: list of users and roles
2SELECT dp.NAME AS principal_name,
3 dp.TYPE_DESC AS principal_type_desc,
4 o.NAME AS object_name,
5 p.PERMISSION_NAME,
6 p.STATE_DESC AS permission_state_desc
7FROM sys.database_permissions p
8 LEFT OUTER JOIN sys.all_objects o
9 ON p.MAJOR_ID = o.OBJECT_ID
10 INNER JOIN sys.database_principals dp
11 ON p.GRANTEE_PRINCIPAL_ID = dp.PRINCIPAL_ID;