Details about existing roles and users in azure sql database

azure-sql-databaseazure-sql-managed-instanceroleusers

I would like to get details of all users existing in a sql server DB and the respective roles they are part of and the permissions granted/denied for the a role/user.

what is the best way to get this details?

Best Answer

If you are talking about Azure SQLDB or Managed instance you can use this script:

SELECT role.name AS RoleName,
member.name AS MemberName
FROM sys.database_role_members rolemember JOIN sys.database_principals AS role
ON rolemember.role_principal_id = role.principal_id
JOIN sys.database_principals AS member
ON rolemember.member_principal_id = member.principal_id order by 1

I hope this helps.