Skip to content

Instantly share code, notes, and snippets.

@petesql
Created February 20, 2024 00:37
Show Gist options
  • Save petesql/5d7d6ee5bd0e8cd77802b4ff52fb68f5 to your computer and use it in GitHub Desktop.
Save petesql/5d7d6ee5bd0e8cd77802b4ff52fb68f5 to your computer and use it in GitHub Desktop.
SQL Server Get Database File Information
-- Get db filenames, paths, sizes and growth info
SELECT DB_NAME(database_id) AS 'Database Name',
file_id, name, physical_name, type_desc, state_desc,
is_percent_growth, growth,
CONVERT(bigint, growth/128.0) AS 'Growth in MB',
CONVERT(bigint, size/128.0) AS 'Total Size in MB', max_size
FROM sys.master_files WITH (NOLOCK)
ORDER BY DB_NAME(database_id), file_id OPTION (RECOMPILE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment