Query to list all accessible DBs by a given user

Run below query as the user for whom you would like to know all the accessible DBs.

Query:

SELECT [Name] as DatabaseName from master.dbo.sysdatabases
WHERE ISNULL(HAS_DBACCESS([Name]),0)=1
ORDER BY [Name]

Results:

DatabaseName

master

model

msdb

tempdb

 

 

 

 

 

.

Leave a Reply

Your email address will not be published. Required fields are marked *