MSSQL T-SQL to return all the login, return all the DB user and their permission

Elon Musk 161 Reputation points
2023-02-28T03:06:51.8866667+00:00

Recently I have a audit project, need quried all the logins and its permissions. for example, if the login has sysadmin, it break policy and need to decrease the permission

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,677 questions
{count} votes

Accepted answer
  1. Rahul Randive 8,181 Reputation points Microsoft Employee
    2023-02-28T03:36:52.9566667+00:00

    Thanks for your question. 

    Please find reference document for queries listing all permission. 

    https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-database-permissions-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15#examples 

    Similar thread and T-SQL Commands -

    https://learn.microsoft.com/en-us/answers/questions/466580/azure-sql-server-security 

    Let us know if this helps!

     

    Thank you!

    0 comments No comments

0 additional answers

Sort by: Most helpful