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.
- EXEC sp_databases
Method 2: Using sp_helpdb
System stored procedure sp_helpdb reports the information about all database or specific database.The result set of this stored procedure returns database name,size,owner,database Id, created date, status and compatibility level as column
- EXEC sp_helpdb
Method 3: Using system
table “sys.databases“
System table "sys.databases" contains all the databases in the instance of SQL server.
- 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
Hope this help.
- SELECT name FROM sys.sysdatabases

Join the conversation! Your thoughts help the community grow.