SQL Server query to find all current database names

I need an SQL query to search for the names of existing databases.

+52
sql-server
May 16 '09 at 9:50 p.m.
source share
7 answers

Here is a query to display all databases in one Sql engine

Select * from Sys.Databases 
+64
May 16 '09 at
source share
 SELECT name FROM sys.databases 

You will see only those databases for which you have permission.

+42
May 17 '09 at 4:11
source share

Another addition to the mix:

 EXEC sp_databases 
+9
May 17 '09 at 4:30
source share

I do not recommend this method ... but if you want to go stupid and weird:

 EXEC sp_MSForEachDB 'SELECT ''?'' AS DatabaseName' 

or

 EXEC sp_MSForEachDB 'Print ''?''' 
+5
May 17 '09 at 4:36
source share

You can also use the following methods:

 EXEC sp_helpdb 

and

 SELECT name FROM sys.sysdatabases 

Recommended reading:

Remember to take a look at sysdatabases VS sys.sysdatabases

A similar stream .

+4
Jul 02 '13 at 5:26
source share

This forum also offers:

 SELECT CATALOG_NAME AS DataBaseName FROM INFORMATION_SCHEMA.SCHEMATA 
+2
May 16 '09 at PM
source share

For people where " sys.databases " does not work, you can also use this;

 SELECT DISTINCT TABLE_SCHEMA from INFORMATION_SCHEMA.COLUMNS 
+2
Oct 08 '13 at 23:01
source share



All Articles