26 May, 2009
0 Comments
0 categories
To calculate the "size", "used size in" and "free space in" a Microsoft SQL Server 2008 mdf or ldf file use:
use master
go
select name, cast((size/128.0) as int) as TotalSpaceInMB, cast((cast(fileproperty(name, 'SpaceUsed') as int)/128.0) as int) as UsedSpaceInMB, cast((size/128.0 - cast(fileproperty(name, 'SpaceUsed') AS int)/128.0) as int) as FreeSpaceInMB from sys.database_files
Result
For more information on fileproperty, see: http://msdn.microsoft.com/en-us/library/ms188401.aspx
Tags: SQL Server
Thanks for this tip. It sure was of great use to me.