Friday, July 27, 2012

Find permissions of current user

In SQL Server 2005 or above, to find current user's permissions granted.

SELECT
       dp.NAME AS principal_name,
       dp.type_desc AS principal_type_desc,
       o.NAME AS object_name,
       p.permission_name,
       p.state_desc AS permission_state_desc
from  
      sys.database_principals dp
join
     sys.database_permissions p
on
     p.grantee_principal_id = dp.principal_id
left join
     sys.all_objects o
on
     p.major_id = o.OBJECT_ID
--where dp.name=CURRENT_USER
order by principal_name

Note: powerful user can view other users permissions.

No comments: