I just realised that in all my scripts that I use on a regular basis, I didn’t have one for working out free space in SQL Server filegroups. It’s not something that comes up too often but it’s handy to know. For methods of working out space in individual files, you could refer to this post on mssqltips.
-- Free space by filegroup SELECT FILEGROUP_NAME(data_space_id) as FilegroupName, SUM(size/128.0) AS CurrentSizeMB, SUM(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0) AS FreeSpaceMB, ( SUM(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0) / -- FreeSpaceMB (SUM(size/128.0)) -- CurrentSizeMB * 100 -- Convert to percentage ) AS FilegroupPercentFree, COUNT(*) as NumberOfFilesInFilegroup FROM sys.database_files WHERE data_space_id <> 0 GROUP BY FILEGROUP_NAME(data_space_id);

POST #100
I just realised as well that this is post #100 on my blog. I started it just to save some of my queries and ideas. Post #1 was a really simple query but it got me going.




L is the dialect of SQL used with SQL Server and is a declarative language. A declarative language takes the user’s request (or query) and works out the best way how to return the data. This differs from an imperative language in which the programmer tells the program how it should process the statement. With this is mind, it should be fairly easy with some simple syntax just to tell SQL Server what we want and get the results back.