Created
September 7, 2022 04:58
-
-
Save MarshalOfficial/dc34896781ad2a1f2f8a1ccf6f0bc1fb to your computer and use it in GitHub Desktop.
get sql server all dbs size
This file contains hidden or 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
| SELECT [Database Name] = DB_NAME(database_id), | |
| [Type] = CASE WHEN Type_Desc = 'ROWS' THEN 'Data File(s)' | |
| WHEN Type_Desc = 'LOG' THEN 'Log File(s)' | |
| ELSE Type_Desc END, | |
| [Size in MB] = CAST( ((SUM(cast(Size as bigint))* 8) / 1024.0) AS DECIMAL(20,0) ) | |
| FROM sys.master_files | |
| -- WHERE database_id = DB_ID(‘Database Name’) | |
| GROUP BY GROUPING SETS | |
| ( | |
| (DB_NAME(database_id), Type_Desc), | |
| (DB_NAME(database_id)) | |
| ) | |
| ORDER BY CAST( ((SUM(cast(Size as bigint))* 8) / 1024.0) AS DECIMAL(20,0) ) desc --DB_NAME(database_id), Type_Desc DESC | |
| GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment