Tip of the Day : How to Get a List of Databases Within a SQL Server Instance

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - June 23, 2025

How to Get a List of Databases Within a SQL Server Instance

There are different ways of listing all databases within an instance of SQL Server.  The first method is with the use of the sp_databases system stored procedure:

EXEC sp_databases 

The sp_databases lists databases that either reside in an instance of the SQL Server Database Engine or are accessible through a database gateway.

Another way of getting a list of all databases within an instance of SQL Server is with the sp_helpdb system stored procedure.  The sp_helpdb system stored procedure reports information about a specified database or all databases.  If no database name is passed to the sp_helpdb system stored procedure, it will display information about all databases on the server running SQL Server.

EXEC sp_helpdb

Yet another way of getting a list of databases within an instance of SQL Server is by querying the sys.databases system view.

SELECT [Name]
FROM [sys].[databases]

Regardless of which method to use, all of these methods will return not just user databases but system databases as well, such as the master, model, msdb and tempdb databases.  If the SQL Server instance has Reporting Services installed, the ReportServer and ReportServerTempDB databases will also be included in the list.

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions