首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么获取指定数据库所在磁盘的磁盘可用空间

2012-03-16 
如何获取指定数据库所在磁盘的磁盘可用空间如题数据库为sql2005[解决办法]H:\dir h:\m*Volume in drive H

如何获取指定数据库所在磁盘的磁盘可用空间
如题
数据库为sql2005

[解决办法]
H:\>dir h:\m*
 Volume in drive H is xxxxxx
 Volume Serial Number is 0000-0000

 Directory of h:\

03/09/2009 12:55p <DIR> My Databases
04/29/2010 12:19p <DIR> My AppData
05/03/2010 08:08p <DIR> My Documents
11/06/2008 05:07p <DIR> My Data
0 File(s) 0 bytes
4 Dir(s) 220,545,024 bytes free

H:\>
[解决办法]
执行下面的sql可以得到当前所在的数据库的数据文件所在的盘符的剩余空间(MB)

declare @drivename char(1)
select @drivename=left(filename,1) from sysfiles where fileid= 1

if not exists(select 1 from tempdb.dbo.sysobjects where name like '#FreeSpace%' and type='U')
create table #FreeSpace(
Drive char(1),
MB_Free int
)
else
truncate table #FreeSpace

insert into #FreeSpace 
exec xp_fixeddrives

select MB_Free from #FreeSpace where Drive = @drivename
go


热点排行