Listing Log File Sizes of All Databases in SQL Server

Hello everyone,

In this article, I will provide information about listing log file sizes of all databases in SQL Server.

In SQL Server, in some cases we may want to list the log file sizes of all databases.

You can easily do this with the help of the code below.

WITH fs
AS (SELECT database_id,
           type,
           size * 8.0 / 1024 SIZE
    FROM sys.master_files)
SELECT name,
       (
           SELECT SUM(SIZE)
           FROM fs
           WHERE type = 0
                 AND fs.database_id = db.database_id
       ) DataFileSizeMB,
       (
           SELECT SUM(SIZE)
           FROM fs
           WHERE type = 1
                 AND fs.database_id = db.database_id
       ) LogFileSizeMB
FROM sys.databases db;

When you run the code, you will get a result like the one below.

Listing Log File Sizes of All Databases in SQL Server

As you can see, the log file sizes of all databases are listed.

Good luck to everyone in business and life.

265 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!