Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

SQL Server - How to Get Database Size in SQL Server 2008

Dec 4, 2013
Introduction:

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



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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

priya said...

nice article to read..

Anonymous said...

nice article.more informative to us.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.