I need a SQL query to find the names of existing databases.
I need a SQL query to find the names of existing databases.
SELECT name
FROM sys.databases
You'll only see the databases you have permission to see.
I don't recommend this method... but if you want to go wacky and strange:
EXEC sp_MSForEachDB 'SELECT ''?'' AS DatabaseName'
or
EXEC sp_MSForEachDB 'Print ''?'''