Get Database Size in MS SQL Server

Posted: October 5, 2013 in SQL

MS SQL Database Size in KB, MB and GB

There are couple of different ways of get Database size. One of them is given below which shows the DB Id, Database Name, Database Logical Name, File Size in KB, MB and GB. This shows size for both .mdf and .ldf file.

SELECT
     db.[dbid] as 'DB ID',
     db.[name] as 'Database Name',
     af.[name] as 'Database Logical Name',
     af.[size] * 8 as 'File Size (KB)',
     CAST((((CAST(af.[size] as DECIMAL(18,4)) * 8192) /1024) /1024) AS DECIMAL(18,4)) as 'File Size (MB)',
     CAST(((((CAST(af.[size] as DECIMAL(18,4)) * 8192) /1024) /1024) /1024) AS DECIMAL(18,4)) as 'File Size (GB)', 
     af.[filename] as 'Physical Name'
FROM 
     SYS.SYSDATABASES db
     INNER JOIN SYS.SYSALTFILES af ON db.dbid = af.dbid
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s