Friday, April 25, 2014

How can I get the list of available databases on a SQL server instance?

Whenever you want to get the list of available databases on an instance you could use this query. You could also change it as will fit you better. This query it is helpful when you need a list of databases and the list is big, of course.

Query that runs well for Sql Server 2012:
SELECT * 
FROM sys.databases d
WHERE d.name NOT IN ('master', 'tempdb', 'model', 'msdb', 'ReportServer', 'ReportServerTempDB');
--or you could use a simpler condition which in my opinion is not so relevant 
--WHERE d.database_id > 4

Otherwise you could also use:
EXEC sp_databases

Cheers, Adrian

No comments:

Post a Comment