Volume info for all databases on the current instance SQL Server
- Kunal Ranpura
- Jul 29, 2019
- 1 min read
-- Volume info for all databases on the current instance (SQL Server 2008 R2 SP1 or greater)
SELECT DB_NAME(f.database_id) AS [DatabaseName], f.file_id,
vs.volume_mount_point, vs.total_bytes/1024000000 Total_Drive_Space_GB, vs.available_bytes/1024000000 Available_GB,
CAST(CAST(vs.available_bytes AS FLOAT)/ CAST(vs.total_bytes AS FLOAT) AS DECIMAL(18,1)) * 100 AS [Space_Available%]
FROM sys.master_files AS f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.file_id) AS vs
ORDER BY f.database_id OPTION (RECOMPILE);
Komentar