Beyondrelational

Wednesday, June 9, 2010

How to monitor disk free space?

Execute the following script in Query Editor to create a table as free space log and deploy the insert script into SQL Server Agent for daily, weekly, etc. execution. Database files used space can be obtained by sp_helpfiles command.

CREATE TABLE DBDiskFree (
DBDiskFreeID INT identity(1,1) primary key,
DriveLetter CHAR(1) NOT NULL,
FreeMB INTEGER NOT NULL,
DateStamp datetime default (getdate()))
GO

/* Populate DBDiskFree with data */
INSERT INTO DBDiskFree (DriveLetter, FreeMB )
EXEC master..xp_fixeddrives
GO

SELECT *,(FreeMB/1024)FreeGB FROM DBDiskFree
GO
Drop Table DBDiskFree
GO

No comments:

Post a Comment