SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

List all permission in all databases

By Alejandro Pelc, 2009/04/16

Total article views: 6241 | Views in the last 30 days: 895

This is a very simple script that will create a table variable and fill it with all the users and roles permission for each object on all the databases (can be easily changed to get the permission of only one database or custom ones). The usage is really easy, just paste it on Management Studio and execute it.

The script creates three table variables (@dbs, @permission and @objects), one for storing the databases' names (@dbs), other to store the permission (@permission) and the third for storing the databases objects (@objects).

When the script runs, it will fill the @dbs with all the databases on the server, including snapshots. Then, it'll loop through the table, using the database name, to fill the @objects table. Finally, it'll join the @objects table with the sys.database_principals and sys.database_permissions to retrieve the permission and fill the @permission table. This operation will be performed on each database on the @dbs table. In case you want to get the permission for specific databases, just change the line that inserts the databases name from the sys.databases for the custom one.

By Alejandro Pelc, 2009/04/16

Total article views: 6241 | Views in the last 30 days: 895
Your response
 
 
Related tags

Security    
 
Related content

What UDP port does SQL Server listen on?...

By Steve Jones | Category: Security
(not yet rated) | 5,700 reads

Mary is a member of a SQL Server...

By Steve Jones | Category: Security
(not yet rated) | 3,224 reads

How would you turn on C2-Level auditing?

By Steve Jones | Category: Security
(not yet rated) | 2,360 reads

You have SQL Server 2000 service pack 3a...

By Steve Jones | Category: Security
(not yet rated) | 2,201 reads
 
Contribute
Like this? Try these...

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com