Friday, January 29, 2021

Get database file info

Ever wondered where your SQL Server database files are actually stored? This handy query helps you quickly find the **file names and physical paths for all user and system databases** on your instance. It's a great way to get an overview of your database file locations and properties.

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);

This query pulls information from the sys.master_files catalog view, which provides details about the files in your SQL Server instance.

Popular Posts