Nucleus Datakonsult sp_dbinfo - show space usage for all databases

Home

About me and Nucleus
Partners

Articles, tips etc.
My blog
Links
Microsoft articles
Forums

Courses and training




Microsoft Most Valuable Professional


Skor
R

Overview
One of the first things I want to do when I look at a new SQL Server is to get an idea of space usage details for each database, as well as total.

Versions etc.
See comment block in procedure source code for version history of the procedure.

Details
The procedure returns a row for each database plus one row for all databases. You get the name of the database, data space allocated, data space used, log space allocated and log space used. All units are MB. The procedure accepts two parameters, both optional.

@sort is used for sorting the result. The value is a single letter:
valuemeaning
'n'database name (default)
'd'data space allocated
'l'log space allocated
'r'rollup information only

@include_instance_name ('y' or 'n') specified whether to include the instance name in the result set.

Usage examples
EXEC sp_dbinfo
EXEC sp_dbinfo 'n'
EXEC sp_dbinfo 'd'
EXEC sp_dbinfo 'l'
EXEC sp_dbinfo 'l', 'y'


Example result
database_namedata_allocateddata_usedlog_allocatedlog_used
Adventureworks200818017910
Credit262430
master4210
Utilities3110
[ALL]247234387

The code:
You find the code here