Thursday 8 November 2012

Permission List in SQL SERVER 2005

This script gives a detailed information about permission for users in a database. This output lists Object name, Schema name, user name and permission. This is compatible only to SQL 2005.
Script
select b.name,c.name,
user_name(a.grantee_principal_id) as UserName,a.permission_name,
case a.state
when 'W' then 'With Grant Option'
when 'G' then 'Grant'
When 'D' then 'Deny'
Else ''
end as PermissionType
from sys.database_permissions a,sys.all_objects b,sys.schemas c
where b.object_id=a.major_id
and a.grantee_principal_id<>0
and a.grantee_principal_id<>2
and b.schema_id=c.schema_id

No comments:

Post a Comment