users assigned a sql azure role

拜拜、爱过 提交于 2019-12-03 17:09:36

问题


I am trying to make sure that all users have been assigned a particular role. Is there any view or SQL query for getting this information?


回答1:


The views have changed names but the following should work against 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



回答2:


I believe the query listed below should list the users and roles of a single database

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

Or for all DBs on a SQL instance you can use 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'


来源:https://stackoverflow.com/questions/7669193/users-assigned-a-sql-azure-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!