Database Size

DECLARE @dbName VARCHAR(100)
SET @dbName='DATABASE_NAME'
Select 
    sd.name as DBName
    ,mf.name as FileName
    ,case mf.file_id
        when 1 then 'Main'
        when 2 then 'Log'
    END as FileType    
    ,mf.file_id
    ,CONVERT(varchar(100), Convert(decimal(10,2),(((Sum(Convert(decimal(10,2),mf.size)) 
*
8000)/1024)/1024)))+' MB' as SIZE from sys.databases sd join sys.master_files mf on sd.database_ID = mf.database_ID AND sd.name=@dbName GROUP BY sd.name,mf.name,mf.database_id,mf.file_id

The above script when @dbName is set calculates the size of a database for the mdf and log file seperately.

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