lordbeazley
5/15/2013 - 7:11 AM

Show space used by the current database (by file and aggregate).

Show space used by the current database (by file and aggregate).

select
	[db] = null,
	[name],
	[data_space_id],
	[physical_name],
	[GB] = Ceiling(([size] * 8) / 1024.0 / 1024.0),
	[MB] = Ceiling(([size] * 8) / 1024.0),
	[KB] = Ceiling(([size] * 8) / 1.0)
from sys.database_files
union
select
	[db] = db_name(),
	[name] = null,
	[data_space_id] = null,
	[physical_name] = null,
	[GB] = Ceiling((Sum([size]) * 8) / 1024.0 / 1024.0),
	[MB] = Ceiling((Sum([size]) * 8) / 1024.0),
	[KB] = Ceiling((Sum([size]) * 8) / 1.0)
from sys.database_files
order by
	[db] desc,
	[data_space_id] asc,
	[name] asc ;