Sunday, May 23, 2021

Get the list of all databases on a server in SQL Server

Find List of all databases in sql server use the below methods. 

Method 1: 

Below query will be applicable for SQL Server 2000+ version (Contains 12 columns)

SELECT * FROM dbo.sysdatabases

Method 2: 

Below query extract information about databases with more information (ex: State, Isolation, recovery model etc.)

Note: This is a catalog view and will be available SQL SERVER 2005+ versions

SELECT * FROM sys.databases

Method 3: 

To see just database names you can use undocumented sp_MSForEachDB

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

Method 4: 

Below SP will help you to provide database size along with databases name , owner, status etc. on the server.

EXEC sp_helpdb

Method 5 

Similarly, below stored procedure will give database name, database size and Remarks

EXEC sp_databases

Related Article:

No comments:

Post a Comment