The list databases command shows every database stored on the current SQL Server instance.
Run SELECT name FROM sys.databases;
. It queries the system catalog and returns every database name immediately.
Select more columns from sys.databases
, such as create_date
, owner_sid
, and size
. The system view exposes dozens of metadata attributes.
Add a WHERE
clause. For example, WHERE name LIKE '%Sales%'
only shows databases relevant to your ecommerce data warehouse.
Attach ORDER BY create_date DESC
to surface the newest databases first.
sys.databases
over sp_helpdb
?sys.databases
offers better performance, a tabular result set, and full support for WHERE
and ORDER BY
. It is the modern, documented method.
Listing databases is read-only and low-impact. You can safely execute it anytime, even on busy servers, to verify backup targets or housekeeping jobs.
VIEW ANY DATABASE
Limit visibility by granting VIEW ANY DATABASE
instead of sysadmin
. Users see database names but cannot access data.
Only the VIEW ANY DATABASE
permission is required. Sysadmins implicitly have this right, but lower-privileged roles can be granted it explicitly.
No. Reading sys.databases
is a metadata lookup held entirely in memory. It does not lock user tables or affect performance.
Yes. Connect to the remote instance first, then run the same SELECT
statement. Tools like Galaxy or SQLCMD support remote connections.