March 29, 2024 at 12:00 am
Comments posted to this topic are about the item Check Azure SQL DB Space Used
April 3, 2024 at 1:59 am
There's potential for deleted databases to show up as well, a join to sys.databases will prevent that:
SELECT
[database_name],
start_time AS 'LastCollectionTime',
storage_in_megabytes AS 'CurrentSize(MBs)',
allocated_storage_in_megabytes AS 'AllocatedStorage(MBs)'
FROM (
SELECT
ROW_NUMBER() OVER(PARTITION BY [database_name] ORDER BY start_time DESC) AS rn,
[database_name],
start_time,
storage_in_megabytes,
allocated_storage_in_megabytes
FROM sys.resource_stats
) rs
INNER JOIN sys.databases d ON d.name = rs.database_name
WHERE rn = 1
(with a performance hit as usual)
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply