SQLSERVER查看各磁盘可用空间
来源:这里教程网
时间:2026-03-02 11:13:32
作者:
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: <DBA>
-- Create date: <2012-11-16>
-- Description: <get_disk_size>
-- =============================================
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 as 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查看各磁盘可用空间03-02
- Sqlserver 2014 alwayson 架构添加辅助节点上的数据库03-02
- SQL Server 日志传送配置03-02
- Ubuntu df命令详解(新手也能轻松查看磁盘空间使用情况)03-02
- Sqlserver数据写入表测试03-02
- 小型视频监控系统设计方案03-02
- 绿联的HDMI矩阵设备连接说明03-02
- error: 26 - 定位指定的服务器/实例时出错 处理03-02
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- SQL Server 日志传送配置
SQL Server 日志传送配置
26-03-02 - Ubuntu df命令详解(新手也能轻松查看磁盘空间使用情况)
Ubuntu df命令详解(新手也能轻松查看磁盘空间使用情况)
26-03-02 - Sqlserver数据写入表测试
Sqlserver数据写入表测试
26-03-02 - 小型视频监控系统设计方案
小型视频监控系统设计方案
26-03-02 - 绿联的HDMI矩阵设备连接说明
绿联的HDMI矩阵设备连接说明
26-03-02 - error: 26 - 定位指定的服务器/实例时出错 处理
error: 26 - 定位指定的服务器/实例时出错 处理
26-03-02 - 设计实施参考标准,GB 50174 关于信息化中心机房建筑高度的规定
设计实施参考标准,GB 50174 关于信息化中心机房建筑高度的规定
26-03-02 - 室外立杆安装摄像机,防雷接地电阻不应大于10欧姆
室外立杆安装摄像机,防雷接地电阻不应大于10欧姆
26-03-02 - 开启sqlserver2014导入EXCEL功能
开启sqlserver2014导入EXCEL功能
26-03-02 - 天兔监控SQL Azure报错解决案例
天兔监控SQL Azure报错解决案例
26-03-02
