Today I am gonna talk about the requirement of finding out all permissions for a user in all or selective databases.
The query here will help you in following situations:
- Customer has provided you with a user id and couple of database names and they wanted to find out all the permissions the user has on those databases.
- You have a task to provide access for a user id to some of the databases. You have provided the access and now want to pull the report to send to customer.
- You have been given a user id and asked to find out all permissions in all user databases.
This may not be exactly what you are looking for but certainly will give you some idea to make it your way.
Retrieve all permissions for a user in selective databases:
Query for Selective Database(s) permissions
In this example I have listed the permissions for “Test_User” on databases “database1” and “database2″as shown the below screen shot:
Retrieve all permissions for a user in all user databases:
Download the code:
Here is an example output:
Please feel free to let me know if there is any better way you can think of to retrieve the same information.
Check out the below scripts as well:
Script to retrieve database backup information
Script to get SQL Cluster Failover Time and Node Name prior to Failover
Script to List All Users with db_owner role in SQL 2000