List of a available DBs on SQL server instance

SELECT name FROM master.dbo.sysdatabases

To exclude non-user DBs:

... WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb');

or

SELECT *
FROM sys.databases d
WHERE d.database_id > 4

Leave a Reply