SQL Server Admin
T-SQL Articles

October 13, 2010

Get Free Disk space using SQL Server




In order to programmatically determine Free Hard Disk Space using T-SQL, use the extended stored procedure master.dbo.xp_fixeddrives which returns a list of all hard drives and the free space(in MB) for each of the hard drive.

DECLARE @OSDriveSpace TABLE
(
DriveNm char(1),
FreeDriveSpaceInMB int
)

INSERT INTO @OSDriveSpace
EXEC master.dbo.xp_fixeddrives

SELECT * FROM @OSDriveSpace

Note: The T-SQL query shown above does not take into account Volume Mount Points. If you need to include mount points and monitor them, then make sure you check out this article CLR stored procedure to get disk space information which shows how to use a CLR stored procedure to return the capacity and free space of a mount point.

OUTPUT

image


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter



 
  Feedback:

comments

0 Responses to "Get Free Disk space using SQL Server"
 

Copyright © 2009-2011 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions