sp_dbinfo - database space usage information

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.

sp_dbinfo.sql (doesn't support secondary databases in AG)
sp_dbinfo_AG.sql (excludes non-readable secondary databases in AG, requires SQL 2012)

Versions
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