返回顶部
首页 > 资讯 > 服务器 >SqlServer查看数据库信息及服务器级、数据库级、数据库独立 用户权限
  • 763
分享到

SqlServer查看数据库信息及服务器级、数据库级、数据库独立 用户权限

摘要

sqlserver数据库信息、数据库权限 --数据库清单 SELECT * FROM Master..SysDatabases ORDER BY Name; --服务器级用户权限 WIT

SqlServer查看数据库信息及服务器级、数据库级、数据库独立 用户权限

sqlserver数据库信息、数据库权限
--数据库清单
SELECT * FROM Master..SysDatabases ORDER BY Name;  

--服务器级用户权限
WITH CTE AS
(
SELECT u.name AS UserName,
u.is_disabled AS IsDisabled,
g.name as svrRole,
"" as "flag"
FROM sys.server_principals u
INNER JOIN sys.server_role_members m ON u.principal_id = m.member_principal_id
INNER JOIN sys.server_principals g ON g.principal_id = m.role_principal_id
)
SELECT * FROM CTE PIVOT(MAX(flag) FOR svrRole IN ([public],
[sysadmin],
[securityadmin],
[serveradmin],
[setupadmin],
[processadmin],
[diskadmin],
[dbcreator],
[bulkadmin])) as rg;

--数据库级用户权限
WITH CTE AS
(
SELECT u.name AS UserName,
g.name AS dbRole,
"" as "flag"
FROM sys.database_principals u
INNER JOIN sys.database_role_members m ON u.principal_id = m.member_principal_id
INNER JOIN sys.database_principals g ON g.principal_id = m.role_principal_id
)
SELECT * FROM CTE PIVOT(MAX(flag) FOR dbRole IN ([public],
[db_owner],
[db_accessadmin],
[db_securityadmin],
[db_ddladmin],
[db_backupoperator],
[db_datareader],
[db_datawriter],
[db_denydatareader],
[db_denydatawriter])) as rg;

--数据库级独立用户权限
select c.name as UserName,b.name as ObjectName,
CASE b.type
WHEN "U" THEN "Table"
WHEN "P" THEN "Procedure"
ELSE "OTHER"
END AS ObjectType,
CASE WHEN a.ACTioN = 26 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "REFERENCES",
CASE WHEN a.ACTION = 193 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "SELECT",
CASE WHEN a.ACTION = 195 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "INSERT",
CASE WHEN a.ACTION = 197 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "UPDATE",
CASE WHEN a.ACTION = 196 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "DELETE",
CASE WHEN a.ACTION = 224 AND a.PROTECTTYPE = 205 THEN "" ELSE "" END AS "EXECUTE",
CASE a.PROTECTTYPE
WHEN 204 THEN "GRANT_W_GRANT"
WHEN 205 THEN "GRANT"
WHEN 206 THEN "DENY"
ELSE "OTHER"
END AS ProtectType
from sysprotects a inner join sysobjects b on a.id = b.id
inner join sysusers c on a.uid = c.uid order by c.name,b.name

 

--结束END--

本文标题: SqlServer查看数据库信息及服务器级、数据库级、数据库独立 用户权限

本文链接: https://lsjlt.com/news/6701.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作