Skip to content

Instantly share code, notes, and snippets.

@jeremybeavon
Created February 16, 2015 02:02
Show Gist options
  • Save jeremybeavon/8e7f82466c26800022a6 to your computer and use it in GitHub Desktop.
Save jeremybeavon/8e7f82466c26800022a6 to your computer and use it in GitHub Desktop.
Find sizes of all databases on a server
SELECT
database_name = DB_NAME(database_id)
, log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
GROUP BY database_id
ORDER BY total_size_mb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment