SQL query to get the list of SQL accounts and AD accounts having access on database/synapse and their accessibility

Priya Jha 896 Reputation points
2023-01-05T07:26:25.913+00:00

Hi All,

I am using the below query to get the account details and their accessibility:
SELECT r.name role_principal_name, m.name AS member_principal_name
FROM sys.database_role_members rm
JOIN sys.database_principals r
ON rm.role_principal_id = r.principal_id
JOIN sys.database_principals m
ON rm.member_principal_id = m.principal_id

But this does not provide the accounts having granular access like access on particular table or schema, etc.

Can someone please help me with this query improvement?

Azure SQL Database
{count} votes

Accepted answer
  1. Nandan Hegde 36,151 Reputation points MVP Volunteer Moderator
    2023-01-05T13:46:36.837+00:00

    The below query can work :

    select princ.name,princ.type_desc,perm.permission_name,perm.state_desc,perm.class_desc,object_name(perm.major_id)
    from
    sys.database_principals princ
    left join sys.database_permissions perm on perm.grantee_principal_id = princ.principal_id--List database roles & members

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.