Tuesday, 1 September 2009

Determine Space Available in FileGroups

Sometimes its useful to know the space usage of individual database files. The following script uses the FILEPROPERTY function to display the space used by that file.


SELECT DB_NAME() AS DbName,
name AS FileName,
size/128.0 AS CurrentSizeMB,
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0 AS FreeSpaceMB
FROM sys.database_files;