Friday, March 24, 2017

How to get list of all databases in SQL Server


Sometimes there may be requirement of a user to get the list of all databases which exist in the SQL database management studio. The user may use this list to populate a dropdown menu, create a checkbox list, etc.

To get the list of databases, the user can use any of the following methods:


Method 1:

SELECT name FROM dbo.sysdatabases;



Method 2:

EXEC sp_databases;



Method 3:

SELECT name FROM sys.master_files;



Method 4:

EXEC sp_helpdb;



Method 5:

EXEC sp_msForEachDB 'PRINT ''?''';





Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: