用户权限列表

时间:2010-11-13 13:27:47

标签: sql-server sql-server-2005 tsql

有人可以帮我吗?

如何获取SQL Server 2005中特定数据库的数据库级权限用户列表?

1 个答案:

答案 0 :(得分:3)

简单Google搜索,查询来自the first result

 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_permissions p
 left    OUTER JOIN sys.all_objects o
 on     p.major_id = o.OBJECT_ID
 inner   JOIN sys.database_principals dp
 on     p.grantee_principal_id = dp.principal_id

稍微修改以包括数据库名称:

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,
    d.[name] as database_name
from sys.database_permissions p
left OUTER JOIN sys.all_objects o on p.major_id = o.OBJECT_ID
inner JOIN sys.database_principals dp on p.grantee_principal_id = dp.principal_id
left outer JOIN sys.sysdatabases d on d.sid = dp.sid