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.
The code (doesn't support secondary databases in AG) The code (excludes support secondary databases in AG, requires 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:
database name (default)
data space allocated
log space allocated
rollup information only
@include_instance_name ('y' or 'n') specified whether to include the instance name in the result set.