본문 바로가기

MS SQL Server/Administration&Management

Server 레벨 계정 Role 및 권한 보기

SQL Server Server 레벨 계정 Role 및 권한 보기

/*2015-02-02 SQLDBWook@gmail.com*/
USE master

go

/*몰아보기*/
SELECT USP.name AS UserID
, SSP.name COLLATE Korean_Wansung_CI_AS AS RoleName 
, 'Role' AS DivisionCode
  FROM sys.server_role_members AS RM
  JOIN sys.server_principals AS SSP
ON RM.role_principal_id = SSP.principal_id
  JOIN sys.server_principals AS USP
ON RM.member_principal_id = USP.principal_id
UNION ALL
SELECT USP.name AS UserID
, SPR.permission_name AS PermissionName
, 'Permission' AS DivisionCode
  FROM sys.server_principals AS USP
  JOIN sys.server_permissions AS SPR
ON USP.principal_id = SPR.grantee_principal_id
 WHERE SPR.state = 'G' --Grant만 보기
 ORDER BY UserID
, DivisionCode DESC
, RoleName

/*따로보기*/
--#01 ServerRole
SELECT USP.name AS UserID
, SSP.name AS RoleName
,
  FROM sys.server_role_members AS RM
  JOIN sys.server_principals AS SSP
ON RM.role_principal_id = SSP.principal_id
  JOIN sys.server_principals AS USP
ON RM.member_principal_id = USP.principal_id
--#02 ServerPermissions
SELECT USP.name AS UserID
, SPR.permission_name AS PermissionName
,
  FROM sys.server_principals AS USP
  JOIN sys.server_permissions AS SPR
ON USP.principal_id = SPR.grantee_principal_id