我曾经跟随在Azure SQL数据库中创建角色,为角色授予权限并将角色分配给用户:
CREATE ROLE [DepartmentReadOnly] AUTHORIZATION [dbo]
GO
GRANT SELECT ON tblDepartment TO DepartmentReadOnly
CREATE USER [user1] FROM LOGIN [user1];
EXEC sp_addrolemember DepartmentReadOnly, user1;
现在我用什么sql从数据库中检索DepartmentReadOnly角色名称和权限以及user1用户信息,包括user1属于哪个角色?
Azure中没有显示sys.server_principals系统视图,所以我迷路了。有人可以帮忙吗?
答案 0 :(得分:1)
"从sys.sql_logins"中选择*在azure中用作sys.server_principals,您必须在master db
中运行查询答案 1 :(得分:0)
听起来您正在用户数据库中查找这些目录视图:
答案 2 :(得分:0)
这是有效的:
SELECT p.[name] as 'Principal_Name',
CASE WHEN p.[type_desc]='SQL_USER' THEN 'User'
WHEN p.[type_desc]='DATABASE_ROLE' THEN 'Role' END As 'Principal_Type',
--principals2.[name] as 'Grantor',
dbpermissions.[state_desc] As 'Permission_Type',
dbpermissions.[permission_name] As 'Permission',
CASE WHEN so.[type_desc]='USER_TABLE' THEN 'Table'
WHEN so.[type_desc]='SQL_STORED_PROCEDURE' THEN 'Stored Proc'
WHEN so.[type_desc]='VIEW' THEN 'View' END as 'Object_Type',
so.[Name] as 'Object_Name'
FROM [sys].[database_permissions] dbpermissions
LEFT JOIN [sys].[objects] so ON dbpermissions.[major_id] = so.[object_id]
LEFT JOIN [sys].[database_principals] p ON dbpermissions. [grantee_principal_id] = p.[principal_id]
LEFT JOIN [sys].[database_principals] principals2 ON dbpermissions.[grantor_principal_id] = principals2.[principal_id]
WHERE p.principal_id > 4
http://elena-sqldba.blogspot.com/2015/06/retrieving-all-user-created-users-roles.html