forked from ktaranov/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet_Database_Size_With_Graph.sql
More file actions
19 lines (18 loc) · 960 Bytes
/
Get_Database_Size_With_Graph.sql
File metadata and controls
19 lines (18 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Author: Denis Gobo
Original link: http://sqlservercode.blogspot.ru/2017/11/use-t-sql-to-create-caveman-graphs.html
*/
SELECT database_name = DB_NAME(database_id)
, TotalSizeGB = CAST(SUM(size) * 8.0 / 1024/1024 AS DECIMAL(30,2))
, PercentSize = (CONVERT(decimal(30,4), (SUM(size) /
(SELECT SUM(CONVERT(decimal(30,4),size))
FROM sys.master_files WITH(NOWAIT)))
) * 100.00)
, Graph = replicate('|', ((convert(decimal(30,2), (SUM(size) /
(SELECT SUM(CONVERT(decimal(30,2),size))
FROM sys.master_files WITH(NOWAIT)))) * 100)
)
)
FROM sys.master_files WITH(NOWAIT)
GROUP BY database_id
ORDER BY PercentSize DESC;