Pages

Tuesday, February 8, 2011

Find permissions assosiated with USERS DB Level

Find permissions assosiated with USERS DB Level

select A.name 'USER NAME',A.type_desc 'TYPE OF USER',A.default_schema_name 'DEFAULT SCHEMA',
'Permission type' = Case B.role_principal_id
when 0 Then 'public'
when 16384 Then 'db_owner'
when 16385 Then 'db_accessadmin'
when 16386 Then 'db_securityadmin'
when 16387 Then 'db_ddladmin'
when 16389 Then 'db_backupoperator'
when 16390 Then 'db_datareader'
when 16391 Then 'db_datawriter'
when 16392 Then 'db_denydatareader'
when 16393 Then 'db_denydatawriter'
End
from
sys.database_principals A
Join
sys.database_role_members B on A.principal_id=B.member_principal_id