SQL Server?????????? - ??????
???????????? ???????[ 2014/9/18 10:53:30 ] ??????????????? ?????
???????????????????????????????洢???????????????????????б?????
?????. ?????????
????1. ?????????????????????
????(1) DOS????: fsutil volume diskfree
????C:windowssystem32>fsutil volume diskfree C:
????Total # of free bytes : 9789493248
????Total # of bytes : 64424505344
????Total # of avail free bytes : 9789493248
?????????????fsutil?????????????????(file system utility)?????????????Щ?????????????????
????(2) WMI/WMIC: wmic logicaldisk
????WMI???Windows????????????WMIC????????????????WMI????????????????Щ????WMI????????SMS?????????WMI???????API???????????CIM Studio????????????????C++???????????VBScript????????????????????WMI?????????????????WMI???????????????WMIC?????????????????WMI???????????????????????????н???
????C:windowssystem32>wmic logicaldisk get caption??freespace??size
????Caption FreeSpace Size
????C: 9789071360 64424505344
????D: 189013438464 255331397632
???????????wmic??get????????logicaldisk ??????????С?
????(3) ?????????
????LogicalDisk: %Free Space
????LogicalDisk: Free Megabytes
???????С = LogicalDisk: Free Megabytes/ LogicalDisk: %Free Space
??????????????????????????????????????????????????????????á?
????2. SQL ???
????(1) ????洢????xp_cmdshell (????????ò?????????)
DECLARE @Drive TINYINT??
@SQL VARCHAR(100)
DECLARE @Drives TABLE
(
Drive CHAR(1)??
Info VARCHAR(80)
)
SET @Drive = 97
WHILE @Drive <= 122
BEGIN
SET @SQL = 'EXEC XP_CMDSHELL ''fsutil volume diskfree ' + CHAR(@Drive) + ':'''
INSERT @Drives
(
Info
)
EXEC(@SQL)
UPDATE @Drives
SET Drive = CHAR(@Drive)
WHERE Drive IS NULL
SET @Drive = @Drive + 1
END
SELECT Drive??
SUM(CASE WHEN Info LIKE 'Total # of bytes%' THEN CAST(REPLACE(SUBSTRING(Info?? 32?? 48)?? CHAR(13)?? '') AS BIGINT) ELSE CAST(0 AS BIGINT) END)/1024.0/1024/1024 AS TotalMBytes??
SUM(CASE WHEN Info LIKE 'Total # of free bytes%' THEN CAST(REPLACE(SUBSTRING(Info?? 32?? 48)?? CHAR(13)?? '') AS BIGINT) ELSE CAST(0 AS BIGINT) END)/1024.0/1024/1024 AS FreeMBytes??
SUM(CASE WHEN Info LIKE 'Total # of avail free bytes%' THEN CAST(REPLACE(SUBSTRING(Info?? 32?? 48)?? CHAR(13)?? '') AS BIGINT) ELSE CAST(0 AS BIGINT) END)/1024.0/1024/1024 AS AvailFreeMBytes
FROM(
SELECT Drive??
Info
FROM @Drives
WHERE Info LIKE 'Total # of %'
) AS d
GROUP BY Drive
ORDER BY Drive
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11