SQL Server的master数据库中有一个扩展存储过程xp_fixeddrives,可以获取硬盘分区与分区剩余容量,
参考下面代码:
IF OBJECT_ID('#TempDrive') IS NOT NULL
DROP TABLE #TempDrive
CREATE TABLE #TempDrive
(
[DriveName] NVARCHAR(10),
[DriveFreeSpace] BIGINT
)
INSERT INTO #TempDrive
EXECUTE [master].[dbo].xp_fixeddrives
SELECT * FROM #TempDrive