Query to return all users permissions on SQL Server

tobz 161 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
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,976 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
101 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,652 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 112.7K Reputation points MVP
    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/

    0 comments No comments

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

    Hi @tobz

    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".

    0 comments No comments

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.