分享更有价值
被信任是一种快乐

SQLSERVER如何查看各磁盘可用空间

文章页正文上

这篇文章将为大家详细讲解有关SQLSERVER如何查看各磁盘可用空间,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
保存数据的表

create table dc_DiskDetaill
(
Drive varchar(10),
Size varchar(50),
FreeSize varchar(50),
GetTime datetime default(getdate())
)

采集的存储过程

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
— =============================================
— Author:
— Create date:
— Description:
— =============================================
CREATE PROCEDURE [dbo].[Usp_Get_DiskSize]
as
begin
create table #freedisk (drive varchar(50),disksize varchar(100))
insert into #freedisk
exec master.dbo.xp_fixeddrives

EXEC sp_configure ‘show advanced options’, 1
RECONFIGURE
EXEC sp_configure ‘xp_cmdshell’, 1
RECONFIGURE
EXEC sp_configure ‘show advanced options’, 0
RECONFIGURE

create table #a (DiskName varchar(50))
insert into #a
exec xp_cmdshell ‘wmic LOGICALDISK get name’免费主机域名
select IDENTITY(int,1,1) as id ,DiskName into #a1 from #a
drop table #a

create table #b (freespace varchar(50))
insert into #b
exec xp_cmdshell ‘wmic LOGICALDISK get freespace’
select IDENTITY(int,1,1) as id ,freespace into #b1 from #b
drop table #b

create table #c(size varchar(50))
insert into #c
exec xp_cmdshell ‘wmic LOGICALDISK get size’
select IDENTITY(int,1,1)as id,size into #c1 from #c
drop table #c

delete from #a1 where id=1
delete from #b1 where id=1
delete from #c1 where id=1

update #a1 set DiskName=REPLACE(DiskName,’:’,”)
update #a1 set DiskName=REPLACE(DiskName,’ ‘,”)

select id,LEFT(diskname,1) as diskname into #a2 from #a1
drop table #a1

select a.diskname,b.freespace,c.size,getdate() as gettime into #all
from #a2 as a ,#b1 a免费主机域名s b ,#c1 as c where a.id=b.id and a.id=c.id
and a.diskname in (select drive from #freedisk)
drop table #a2
drop table #b1
drop table #c1

update #all set freespace=REPLACE(freespace,’ ‘,”),size=REPLACE(size,’ ‘,”)
select diskname,left(freespace,LEN(freespace)-1) as freespace, left(size,LEN(size)-1) as size,gettime into #all2 from #all
drop table #all

insert into dc_DiskDetaill(Drive,Size,FreeSize,GetTime)
select diskname,cast(size as bigint)/1024/1024 as size,cast(freespace as bigint)/1024/1024 as freesize,gettime from #all2
drop table #all2
EXEC sp_configure ‘show advanced options’, 1
RECONFIGURE
EXEC sp_configure ‘xp_cmdshell’, 0
RECONFIGURE
EXEC sp_configure ‘show advanced options’, 0
RECONFIGURE

drop table #freedisk
end

调用存储过程并查看是否有数据
exec [Usp_Get_DiskSize]

select * from dc_DiskDetaill
关于“SQLSERVER如何查看各磁盘可用空间”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

相关推荐: oracle11gRAC中crsctl命令怎么用

这篇文章将为大家详细讲解有关oracle11gRAC中crsctl命令怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 oracle11gRAC之crsctl命令: 完整的crsctl命令:# su – grid[gri…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册