我创建了Windows用户组,并将这些组作为登录添加到MSSQL 2008 R2实例中。这些组分配了不同的数据库角色。现在我想确定适用于作为其中一个窗口组的用户(x)的有效角色。
是什么方式?
答案 0 :(得分:2)
如果您知道该用户所在的Windows组,您可以在要检查的数据库中使用此组:
select p1.name as role, p2.name as member
from sys.database_role_members m
inner join sys.database_principals p1 on m.role_principal_id = p1.principal_id
inner join sys.database_principals p2 on m.member_principal_id = p2.principal_id
order by 1, 2
如果不这样做,您可以这样做:
-- Impersonate the user
execute as login = '<YourDomain\YourUser>'
-- Check membership
select name as role
from sys.database_principals
where type = 'R' and is_member(name) = 1
-- When ready, revert out of impersonation
revert