How to calculate and get actual Database Size in SQL Server

Recently i have face situation where i have to calculate size of my sql server database for hosting. SQL Server is best database introduced by Microsoft. You will find too many versions from SQL Server 2000/2005/2008/2012/2014/R2 versions. It's very easy to get db size in sql server.  

Here I have shared simple T-SQL query, using this query you will get DB name, Log file size, row size and total size.

SELECT 
      database_name = DB_NAME(database_id)
    , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
WHERE database_id = DB_ID() -- for current db 
GROUP BY database_id 

How to use this query
select database, copy- paste and run...!

output
get-database-size-in-sql-server


Search Terms : Get database size, calculate database size,query to get DB size, get db size in sql server