1

我曾经在 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 系统视图,所以我迷路了。有人可以帮忙吗?

4

3 回答 3

1

“select * from sys.sql_logins”在 azure 中用作 sys.server_principals,并且您必须在主数据库中运行查询

于 2015-06-05T19:28:53.403 回答
0

听起来您正在用户数据库中寻找这些目录视图:

于 2015-06-06T04:47:57.093 回答
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

于 2015-06-18T15:54:53.213 回答