Learning File Size Information of MDF and LDF’s in SQL Server
Hello everyone,
In this article, I will provide information about learning the file size information of MDF and LDF’s in SQL Server.
With the help of the code below, you can learn the file size information of all databases in SQL Server.
SELECT DB_NAME(mf.database_id) AS DatabaseName,
mf.physical_name AS PhysicalPath,
size_on_disk_bytes / 1024 / 1024 AS Size
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf
ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
ORDER BY DatabaseName;
When you run the code, you will get a result like the one below.
As you can see, we have learned the file size information of MDF and LDF’s.
Good luck to everyone in business and life.