Retrieving a list of databases from SQL Server

Using following methods, we can get list of all databases on server. 

Method 1: Using sp_databases
 
System stored procedure "sp_databases"  lists databases of SQL server instance.
  1. EXEC sp_databases  
The result set of this stored procedure contains Database name, size and remark as column
 
Method 2: Using sp_helpdb
 
System stored procedure sp_helpdb reports the information about all database or specific database.
  1. EXEC sp_helpdb   
The result set of this stored procedure returns database name,size,owner,database Id, created date, status and compatibility level as column 
 
Method 3: Using system table “sys.databases“
 
System table "sys.databases" contains all the databases in the instance of SQL server.
  1. SELECT name FROM sys.databases   
Method 4: Using system table “sys. Sysdatabases”
 
The system table "sys.Sysdatabases" contains all database in instance of SQL Server
  1. SELECT name FROM sys.sysdatabases  
Hope this help. 
Ebook Download
View all
Learn
View all