In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to check the available space of each disk in SQLSERVER. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
A table that saves data
Create table dc_DiskDetaill
(
Drive varchar (10)
Size varchar (50)
FreeSize varchar (50)
GetTime datetime default (getdate ())
)
Collected stored procedure
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.disknameforceb.freespace c.sizeauthorgetdate () 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 as size,cast (freespace as bigint) / 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
Call the stored procedure and see if there is any data
Exec [Usp_Get_DiskSize]
Select * from dc_DiskDetaill
This is the end of the article on "how to check the free space of each disk in SQLSERVER". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.