sp_helpdb (Transact-SQL)


Reports information about a specified database or all databases.

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

Topic link icon Transact-SQL Syntax Conventions

sp_helpdb [ [ @dbname= ] 'name' ]  

[ @dbname= ] 'name'
Is the name of the database for which information is reported. name is sysname, with no default. If name is not specified, sp_helpdb reports on all databases in the sys.databases catalog view.

0 (success) or 1 (failure)

Column nameData typeDescription
namesysnameDatabase name.
db_sizenvarchar(13)Total size of the database.
ownersysnameDatabase owner, such as sa.
dbidsmallintDatabase ID.
creatednvarchar(11)Date the database was created.
statusnvarchar(600)Comma-separated list of values of database options that are currently set on the database.

Boolean-valued options are listed only if they are enabled. Non-Boolean options are listed with their corresponding values in the form of option_name=value.

For more information, see ALTER DATABASE (Transact-SQL).
compatibility_leveltinyintDatabase compatibility level: 60, 65, 70, 80, or 90.

If name is specified, there is an additional result set that shows the file allocation for the specified database.

Column nameData typeDescription
namenchar(128)Logical file name.
fileidsmallintFile ID.
filenamenchar(260)Operating-system file name (physical file name).
filegroupnvarchar(128)Filegroup in which the file belongs.

NULL = file is a log file. This is never a part of a filegroup.
sizenvarchar(18)File size in megabytes.
maxsizenvarchar(18)Maximum size to which the file can grow. A value of UNLIMITED in this field indicates that the file grows until the disk is full.
growthnvarchar(18)Growth increment of the file. This indicates the amount of space added to the file each time new space is needed.
usagevarchar(9)Usage of the file. For a data file, the value is 'data only' and for the log file the value is 'log only'.

The status column in the result set reports which options have been set to ON in the database. All database options are not reported by the status column. To see a complete list of the current database option settings, use the sys.databases catalog view.

When a single database is specified, membership in the public role in the database is required. When no database is specified, membership in the public role in the master database is required.

If a database cannot be accessed, sp_helpdb displays error message 15622 and as much information about the database as it can.

A. Returning information about a single database

The following example displays information about the AdventureWorks2012 database.

EXEC sp_helpdb N'AdventureWorks2012';  

B. Returning information about all databases

This following example displays information about all databases on the server running SQL Server.

EXEC sp_helpdb;  

Database Engine Stored Procedures (Transact-SQL)
sys.databases (Transact-SQL)
sys.database_files (Transact-SQL)
sys.filegroups (Transact-SQL)
sys.master_files (Transact-SQL)
System Stored Procedures (Transact-SQL)

Community Additions