Scripts to view SQL Server Database Membership

我的未来我决定 提交于 2020-02-13 14:05:33


use master
go
--Get all logins with sysadmin role.
select b.name,b.type,b.type_desc,c.name
from sys.server_role_members a
inner join sys.server_principals b
on a.member_principal_id = b.principal_id
inner join sys.server_principals c
on a.role_principal_id = c.principal_id

where c.name = 'sysadmin' and c.type='R'
go

use test
go
--Get database users with db_owner role
select b.name,b.type,b.type_desc,c.name
from sys.database_role_members a
inner join sys.database_principals b
on a.member_principal_id = b.principal_id
inner join sys.database_principals c
on a.role_principal_id = c.principal_id
where c.name='db_owner' and c.type='R'

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