Forum Discussion
Denise Child
Jan 20, 2023Iron Contributor
Azure SQL server get all users and their roles
Hello, what are the commands to get a list of all users that have access to an Azure SQL Server? We are using AAD - Universal with MFA to login. I have tried several different ways using Master ...
Kidd_Ip
Jan 21, 2023MVP
Please try this:
List of Users:
SELECT name ,type_desc ,create_date ,CASE WHEN is_disabled = 1 THEN 'Disabled' ELSE 'Enabled' END AS is_disabled FROM sys.sql_logins ORDER BY name
List of Users by role:
SELECT
DP1.name AS DatabaseRoleName
,ISNULL(DP2.name, 'No members') AS DatabaseUserName
,DP2.principal_id
,DP2.create_date
FROM sys.database_role_members AS DRM
RIGHT OUTER JOIN sys.database_principals AS DP1 ON DRM.role_principal_id = DP1.principal_id
LEFT OUTER JOIN sys.database_principals AS DP2 ON DRM.member_principal_id = DP2.principal_id
WHERE DP1.type = 'R'
ORDER BY DP1.name, ISNULL(DP2.name, 'No members');