Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 2.21 KB

sp-databases-transact-sql.md

File metadata and controls

71 lines (51 loc) · 2.21 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_databases (Transact-SQL)
sp_databases lists databases that either reside in an instance of SQL Server, or are accessible through a database gateway.
markingmyname
maghan
randolphwest
07/04/2024
sql
system-objects
reference
sp_databases_TSQL
sp_databases
sp_databases
TSQL

sp_databases (Transact-SQL)

[!INCLUDE SQL Server]

Lists databases that either reside in an instance of the [!INCLUDE ssNoVersion] or are accessible through a database gateway.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_databases
[ ; ]

Return code values

None.

Result set

Column name Data type Description
DATABASE_NAME sysname Name of the database. In the [!INCLUDE ssDE], this column represents the database name as stored in the sys.databases catalog view.
DATABASE_SIZE int Size of database, in kilobytes.
REMARKS varchar(254) For the [!INCLUDE ssDE], this field always returns NULL.

Remarks

Database names that are returned can be used as parameters in the USE statement to change the current database context.

DATABASE_SIZE returns a NULL value for databases larger than 2.15 TB.

sp_databases has no equivalent in Open Database Connectivity (ODBC).

Permissions

Requires CREATE DATABASE, or ALTER ANY DATABASE, or VIEW ANY DEFINITION permission, and must have access permission to the database. Can't be denied VIEW ANY DEFINITION permission.

Examples

The following example shows executing sp_databases.

USE master;
GO
EXEC sp_databases;

Related content