Skip to content

Instantly share code, notes, and snippets.

@BobPusateri
Created February 4, 2023 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobPusateri/40a843e79f153f9df387392becdf9d99 to your computer and use it in GitHub Desktop.
Save BobPusateri/40a843e79f153f9df387392becdf9d99 to your computer and use it in GitHub Desktop.
Gets info about all the files in a specific filegroup
SELECT
a.FILEID As FileID,
a.groupid AS FileGroupID,
a.[name] AS LogicalName,
a.[filename] AS FilePath,
ROUND(CAST(a.size AS FLOAT)/128,2) AS Reserved_MB,
ROUND(CAST(FILEPROPERTY(a.name,'SpaceUsed') AS FLOAT)/128,2) AS Used_MB,
ROUND(CAST(a.size AS FLOAT)/128 - CAST(FILEPROPERTY(a.name,'SpaceUsed') AS FLOAT)/128,2) AS Free_MB
FROM dbo.sysfiles a
WHERE a.groupID = 16
ORDER BY Reserved_MB DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment