I need a SQL query to find the names of existing databases.
+1
A:
This forum suggests also:
SELECT CATALOG_NAME AS DataBaseName FROM INFORMATION_SCHEMA.SCHEMATA
matemaciek
2009-05-16 21:54:23
This didn't work on my machine. MSDN says it is supposed to "contains one row for each database that has permissions for the current user." However the results were limited to only the current database. "SELECT * FROM sysdatabases" works better for me.
beach
2009-05-17 04:42:16
+3
A:
select name from sys.databases
You'll only see the databases you have permission to see.
Remus Rusanu
2009-05-17 04:11:04
A:
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 ''?'''
beach
2009-05-17 04:36:27