DBA - How To Get The Size of All Databases on SQL Server

Here is code that can be used to get the size of Data File (MB), Log File (MB) and Total Size of Database in GB on SQL Server.

       DataFile                        AS DataFileSizeInMB,
       LogFile                         AS LogFileInMB,
       ( DataFile + LogFile ) / 1024.0 AS DataBaseSizeInGB
FROM   (SELECT DB_NAME(Database_id) AS DBName,
               size * 8.0 / 1024    AS SizeInMB,
                 WHEN TYPE = 0 THEN 'DataFile'
                 ELSE 'LogFile'
               END                  AS FileType
        FROM   sys.master_files) D
       PIVOT ( MAX(SizeInMB)
             FOR FileType IN (DataFile,
                              LogFile)) pvt


  1. In the world of www, there are countless blogs. But believe me, this blog has all the perfection that makes it unique in all. I will be back again and again. dba insurance

  2. Cool you write, the information is very good and interesting, I'll give you a link to my site. how to calculate defense base act insurance

  3. Burial insurance is life insurance for seniors for thefinal expense. It helps the person for not becoming any extra burden on the family. This policy provides relief and couarage to the seniors. life insurance

  4. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog.

  5. Hi buddies, it is great written piece entirely defined, continue the good work constantly.
    best agencies in the world

  6. Super site! I am Loving it!! Will return once more, Im taking your food additionally, Thanks. Conversation

  7. Loved the code, its' really helpful for me. Superb article. best PHP calendar and events scripts