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.

Learning File Size Information of MDF and LDF's in SQL Server

As you can see, we have learned the file size information of MDF and LDF’s.

Good luck to everyone in business and life.

197 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!