Last active
September 13, 2022 22:57
-
-
Save petesql/d513e9c4ca22d7949c1360ac89187c1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get sizes of all databases and store into a temp table. | |
SELECT | |
DB_NAME(database_id) AS [database_name], | |
CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2)) AS [data_size_mb], | |
--CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 / 1024 AS DECIMAL(8,2)) AS [data_size_gb], | |
CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2)) AS [log_size_mb], | |
--CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 / 1024 AS DECIMAL(8,2)) AS [log_size_gb], | |
CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2)) AS [total_size_mb] | |
--,CAST(SUM(size) * 8. / 1024 / 1024 AS DECIMAL(8,2)) AS [total_size_gb] | |
FROM sys.master_files WITH(NOWAIT) | |
GROUP BY database_id | |
ORDER BY data_size_mb DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://peter-whyte.com/get-database-sizes-in-sql-server/