sqlserver 查詢使用者角色指令碼

ywxj_001發表於2017-12-25
查詢使用者角色:
select UserName = u.name,DbRole = g.name
from sys.database_principals u, sys.database_principals g, sys.database_role_members m 
where g.principal_id = m.role_principal_id 
and u.principal_id = m.member_principal_id 
order by 1, 2 
go

select DbRole = g.name, MemberName = u.name, MemberSID = u.sid  
from sys.database_principals u, sys.database_principals g, sys.database_role_members m  
where g.principal_id = m.role_principal_id  
and u.principal_id = m.member_principal_id  
order by 1, 2  
go  

select SrvRole = g.name, MemberName = u.name, MemberSID = u.sid  
from sys.server_principals u, sys.server_principals g, sys.server_role_members m  
where g.principal_id = m.role_principal_id  
and u.principal_id = m.member_principal_id  
order by 1, 2  
go  


看伺服器角色:
select 使用者名稱 = u.name,管理員許可權 = g.name,是否在用 = u.is_disabled,MemberSID = u.sid  
from sys.server_principals u, sys.server_principals g, sys.server_role_members m  
where g.principal_id = m.role_principal_id  
and u.principal_id = m.member_principal_id  
and g.name = 'sysadmin'
order by 1, 2
go 





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22996654/viewspace-2149246/,如需轉載,請註明出處,否則將追究法律責任。

相關文章