sp_databases (Transact-SQL)

 

Updated: June 10, 2016

Lists databases that either reside in an instance of the SQL Server or are accessible through a database gateway.

Applies to: SQL Server (SQL Server 2008 through current version).

Topic link icon Transact-SQL Syntax Conventions

  
sp_databases  

None

Column nameData typeDescription
DATABASE_NAMEsysnameName of the database. In the Database Engine, this column represents the database name as stored in the sys.databases catalog view.
DATABASE_SIZEintSize of database, in kilobytes.
REMARKSvarchar(254)For the Database Engine, this field always returns NULL.

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

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

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

The following example shows executing sp_databases.

USE master;  
GO  
EXEC sp_databases;  

sys.databases (Transact-SQL)
HAS_DBACCESS (Transact-SQL)

Community Additions

ADD
Show: