我试图确保所有用户都被分配了一个特定的角色。是否有任何视图或 SQL 查询来获取此信息?
问问题
5741 次
2 回答
29
视图已更改名称,但以下内容应适用于 SQL Azure
select m.name as Member, r.name as Role
from sys.database_role_members
inner join sys.database_principals m on sys.database_role_members.member_principal_id = m.principal_id
inner join sys.database_principals r on sys.database_role_members.role_principal_id = r.principal_id
于 2012-02-20T09:02:39.700 回答
-4
我相信下面列出的查询应该列出单个数据库的用户和角色
select b.name as USERName, c.name as RoleName from dbo.sysmembers a join dbo.sysusers b on a.memberuid = b.uid join dbo.sysusers c on a.groupuid = c.uid
或者对于 SQL 实例上的所有数据库,您可以使用 sp_MSForEachDB
Exec dbo.sp_MSForEachDB 'select ''?'' as DB, b.name as USERName, c.name as RoleName from dbo.sysmembers a join dbo.sysusers b on a.memberuid = b.uid join dbo.sysusers c on a.groupuid = c.uid'
于 2011-11-29T15:09:56.273 回答