Using xp_diskfree

The XP.DLL extended stored procedure xp_diskfree accepts a user-specified drive letter and returns the number of bytes of free space for that drive as an output parameter. To save the return parameter, the caller of the procedure must initialize a variable of datatype int, according to standard SQL Server stored procedure syntax. For example:

declare @outvar int
execute xp_diskfree @drive = 'c' @space = @outvar OUTPUT
select @outvar

When the EXECUTE statement completes, the @outvar variable contains the value returned by the xp_diskfree procedure. If the first three lines in this example were part of a stored procedure in SQL Server itself, the @outvar return value could then be used in subsequent statements.

The xp_diskfree sample code also demonstrates how to implement a default parameter. If the caller executes xp_diskfree without specifying a drive letter parameter, xp_diskfree returns a data row showing free space for the drive on which SQL Server is installed.