How to View SQL Server Database Size and File Locations
How to View SQL Server Database Size and File Locations
SELECT
--database ID
mdf.database_id,
--database name
mdf.name,
--database file location
mdf.physical_name as data_file,
ldf.physical_name as log_file,
db_size_MB = CAST((mdf.size * 8.0)/1024 AS DECIMAL(8,2)),
log_size = CAST((ldf.size * 8.0 / 1024) AS DECIMAL(8,2))
FROM (SELECT * FROM sys.master_files WHERE type_desc = 'ROWS' ) mdf
JOIN (SELECT * FROM sys.master_files WHERE type_desc = 'LOG' ) ldf
ON mdf.database_id = ldf.database_id
--sort DESC or ASC
order by db_size_MB DESC