sql server的許可權查詢
--有關資料庫的許可權查詢:
WITH tree_roles as
(
SELECT role_principal_id, member_principal_id
FROM sys.database_role_members
WHERE member_principal_id = USER_ID('UserName')
UNION ALL
SELECT c.role_principal_id,c.member_principal_id
FROM sys.database_role_members as c
inner join tree_roles
on tree_roles.member_principal_id = c.role_principal_id
)
SELECT distinct USER_NAME(role_principal_id) RoleName
FROM tree_roles
--相關的許可權表
select * from sysusers
select * from syspermissions
具體的一些查詢
--檢視誰可以訪問例項
SELECT
name as UserName, type_desc as UserType, is_disabled as IsDisabled
FROM sys.server_principals
where type_desc in('WINDOWS_LOGIN', 'SQL_LOGIN')
order by UserType, name, IsDisabled
--檢視誰可以訪問資料庫
SELECT
dp.name as UserName, dp.type_desc as UserType, sp.name as LoginName, sp.type_desc as LoginType
FROM sys.database_principals dp
JOIN sys.server_principals sp ON dp.principal_id = sp.principal_id
order by UserType
select * from sys.database_principals
--角色許可權查詢
select
p.name as UserName, p.type_desc as UserType, pp.name as ServerRoleName, pp.type_desc as ServerRoleType
from sys.server_role_members roles
join sys.server_principals p on roles.member_principal_id = p.principal_id
join sys.server_principals pp on roles.role_principal_id = pp.principal_id
where pp.name in('sysadmin')
order by ServerRoleName, UserName
--資料庫角色
SELECT
p.name as UserName, p.type_desc as UserType, pp.name as DBRoleName, pp.type_desc as DBRoleType, pp.is_fixed_role as IfFixedRole
FROM sys.database_role_members roles
JOIN sys.database_principals p ON roles.member_principal_id = p.principal_id
JOIN sys.database_principals pp ON roles.role_principal_id = pp.principal_id
where pp.name in('db_owner', 'db_datawriter')
--檢視使用者的許可權
SELECT
grantor.name as GrantorName, dp.state_desc as StateDesc, dp.class_desc as ClassDesc, dp.permission_name as PermissionName ,
OBJECT_NAME(major_id) as ObjectName, GranteeName = grantee.name
FROM sys.database_permissions dp
JOIN sys.database_principals grantee on dp.grantee_principal_id = grantee.principal_id
JOIN sys.database_principals grantor on dp.grantor_principal_id = grantor.principal_id
where permission_name like '%UPDATE%'
--其它說明
透過儲存過程來查詢
EXEC sp_helprotect NULL, NULL ,null,'golden_ro';
引數1:Owner sysname Name of the object owner
引數2:Object sysname Name of the object.
引數3:Grantee sysname Name of the principal to which permissions were granted
引數4:Grantor sysname Name of the principal that granted permissions to the specified grantee.
暫時列常用的四個引數!用法如上!
如查詢表的授權情況
EXEC sp_helpuser;
引數1:UserName sysname Users in the current database.
引數2:RoleName sysname Roles to which UserName belongs.
引數3:LoginName sysname Login of UserName.
引數4:DefDBName sysname Default database of UserName.
最近在跟使用者授權的時候,發現要授予全部儲存過程的執行許可權,搞了很久,終於搞懂
grant execute to username;
授予單個表、檢視、儲存過程,就比較簡單了!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29371470/viewspace-2141157/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySql查詢使用者許可權MySql
- UserService 查詢使用者查詢許可權 isGlobalQuery分析
- MySQL如何查詢all有哪些許可權?MySql
- 使用LDAP查詢快速提升域許可權LDA
- sql許可權管理SQL
- UserService 查詢使用者沒許可權的索引,增加臨時許可權queryIndicesNoPermission分析索引
- Linux 特殊許可權a,i,t,s以及查詢帶有特殊許可權的所有檔案Linux
- Linux雜記 查詢與特殊許可權位Linux
- MongoDB4.0建立自定義許可權(只有查詢,插入和更新的許可權)的角色步驟MongoDB
- Permission API 統一查詢許可權狀態API
- Sql Server 的引數化查詢SQLServer
- 關於樹結構的查詢優化,及許可權樹的查詢優化優化
- windows server許可權對tomcat的影響WindowsServerTomcat
- sql-server高階查詢SQLServer
- UserService 修改使用者查詢許可權 changeGlobalQuery分析
- UserService 刪除使用者查詢許可權 deleteUserPermission分析delete
- 呼叫者許可權與定義者許可權的pl/sql子程式SQL
- SQL Server查詢慢的解決方案SQLServer
- MongoDB建立只讀使用者並授權指定集合的查詢許可權MongoDB
- SQL Server 查詢歷史執行的SQL語句SQLServer
- 關於SQL Server資料庫中的使用者許可權和角色管理SQLServer資料庫
- SQL Server資料庫檢視login所授予的具體許可權問題SQLServer資料庫
- SQL Server 跨資料庫查詢SQLServer資料庫
- sql-server不相關子查詢SQLServer
- sql-server相關子查詢SQLServer
- UserService 查詢使用者有許可權的關聯索引 queryIndexPatternByUserName分析索引Index
- SQL Server如何匯出db所有使用者許可權建立語句SQLServer
- 許可權之選單許可權
- SQL Server 語句日期格式查詢方法SQLServer
- SQL Server 查詢超時問題排查SQLServer
- SQL Server-簡單查詢語句SQLServer
- linux 檔案許可權 s 許可權和 t 許可權解析Linux
- 查詢SQL Server的歷史執行記錄SQLServer
- Sql Server關於許可權、角色以及登入名、使用者名稱的總結SQLServer
- 如何用 Vue 實現前端許可權控制(路由許可權 + 檢視許可權 + 請求許可權)Vue前端路由
- PostgreSQL訪問許可權查詢函式彙總和使用舉例SQL訪問許可權函式
- SQL SERVER死鎖查詢,死鎖分析,解鎖,查詢佔用SQLServer
- Linux的檔案存取許可權和0644許可權Linux
- 許可權系統:一文搞懂功能許可權、資料許可權