views:

44

answers:

3

Good Morning,

I have connected to my SQL Server 2005 - and have managed to list all of the databases on that server. Now I would like to run a check on each database to see if I have permission to view that database..

How would I go about this?

Many Thanks, Joel

+1  A: 

What do you mean by view the database?!

you can use the following query to list all the permissions on current database:

SELECT * FROM fn_my_permissions (NULL, 'DATABASE');
Wael Dalloul
Yes that's kind of what I want to do - but maybe for a database you aren't connected to? Is that possible?
J Harley
+3  A: 

Firstly, you'll need to find out all of the names in your DB server:

SELECT [name]
  FROM sys.databases;

Then, you'll have to run the following command for each database in order to get the permissions:

USE databaseName;

SELECT *
  FROM fn_my_permissions(null, 'DATABASE')
Ardman
Hello - that seems to work great - however, what would I replaced @dbname with?
J Harley
@J Harley: My bad. I forgot to change that to 'DATABASE'.
Ardman
Perfect that works fine - cheers :)
J Harley
It is a good solution...
ccppjava
A: 

I think you want to look at sys.database_permissions where I think you can query this information.

See here for more info:
http://msdn.microsoft.com/en-us/library/ms188367.aspx

ho1