Share via

Query to return all users permissions on SQL Server

Thelma Obirieze 66 Reputation points
2024-08-27T17:35:11.3233333+00:00

Hi everyone,

Please how can I use TSQL to get the list of all users detailed permissions and privileges on each database.

I want the query to return critieria like:

  • Username
  • Database name
  • Login Type (SQL, Windows user or group, etc)
  • Permission Type
  • Permission State
  • The specified object they have privileges on and they type of privileges.
  • Roles (including the permission type, state and objects for each of the roles)

I need this information in a denormalized form if possible.

Thank you.

SQL Server | SQL Server Transact-SQL
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 134.1K Reputation points MVP Volunteer Moderator
    2024-08-27T21:16:07.83+00:00

    Take a look at this blog post from Sebastian Meine: https://sqlity.net/en/2584/script-database-permissions/

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. LiHongMSFT-4306 31,621 Reputation points
    2024-08-28T02:50:34.6933333+00:00

    Hi @Anonymous

    Try the upvoted answer in this similar thread: SQL Server query to find all permissions/access for all users in a database.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Was this answer helpful?

    0 comments No comments

Your answer

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