我需要确定我的数据库所在驱动器上的可用空间。我知道该xp_fixeddrives
过程,但是如何获取我的数据库所在的特定驱动器的信息?
问问题
18635 次
3 回答
6
像这样的东西?
declare @DatabaseName sysname
set @DatabaseName = 'master'
declare @Drive table(DriveName char, FreeSpaceInMegabytes int)
insert @Drive execute xp_fixeddrives
select
mas.type_desc FileType,
mas.name FileName,
mas.physical_name PhysicalFileName,
mas.size * 8 / 1024 FileSizeInMegabytes,
drv.DriveName,
drv.FreeSpaceInMegabytes
from sys.master_files mas
left join @Drive drv on
left(mas.physical_name, 1) = drv.DriveName
where database_id = db_id(@DatabaseName)
相应地设置@DatabaseName
。
于 2011-11-01T05:44:56.427 回答
5
SELECT Drive
, TotalSpaceGB
, FreeSpaceGB
, PctFree
, PctFreeExact
FROM
(SELECT DISTINCT
SUBSTRING(dovs.volume_mount_point, 1, 10) AS Drive
, CONVERT(INT, dovs.total_bytes / 1024.0 / 1024.0 / 1024.0) AS TotalSpaceGB
, CONVERT(INT, dovs.available_bytes / 1048576.0) / 1024 AS FreeSpaceGB
, CAST(ROUND(( CONVERT(FLOAT, dovs.available_bytes / 1048576.0) / CONVERT(FLOAT, dovs.total_bytes / 1024.0 /
1024.0) * 100 ), 2) AS NVARCHAR(50)) + '%' AS PctFree
, CONVERT(FLOAT, dovs.available_bytes / 1048576.0) / CONVERT(FLOAT, dovs.total_bytes / 1024.0 / 1024.0) * 100 AS PctFreeExact
FROM sys.master_files AS mf
CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.file_id) AS dovs) AS DE
于 2017-11-28T22:44:24.140 回答
1
您还没有提到您的 SQL Server 版本。从 SQL Server 2005 开始,您可以从 sys.database_files 获得大量信息,并将其与 xp_fixeddrives 的输出相关联。
于 2010-02-11T08:39:29.030 回答