Introduction:
Here I will explain how to get database size in SQL server or query to get database size in SQL server 2008.
Here I will explain how to get database size in SQL server or query to get database size in SQL server 2008.
Description:
In previous articles I explained show time difference in minute ago hour ago etc in SQL Server, get list of procedures where table name used in sql, difference b/w view and stored procedure in sql, add row items as string with comma separated values in sql server and many articles relating to SQL server. Now I will explain how to get database size in SQL server.
To get database size in SQL server we need to write the query like as shown below
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 DB_NAME(database_id) = 'master' –-- your database name
GROUP BY
database_id
|
Once we run above code we will get output like as shown
below
Demo
Demo
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
nice article to read..
nice article.more informative to us.
Note: Only a member of this blog may post a comment.