How to get SQL Server all database names

To get all database names uses system stored procedure sp_databases or interogate sys.databases.

Syntax

EXEC sp_databases ;


Examples

SELECT * FROM sys.databases;

USE master;
GO
EXEC sp_databases;

See also: Sp_databases