Calculating The Size of SQL Azure Database and Tables

If you want to see how much size has you used in your SQL Azure database, you can definitely see it on the SQL Azure Developer Portal as shown below.

image_6058D5EB

However, for some reason, sometimes you would either need to get the size more precisely or retrieve the numbers programmatically.

Calculating Database Size

Here’s the query for you to retrieve the size of your database.

select 
      sum(reserved_page_count) * 8.0 / 1024 as ''Database Size''
from 
      sys.dm_db_partition_stats 

After running in on my SQL Server Management Studio R2, here’s the result:

image_6566226C

Calculating Each Table in the Database

If you need to explore in more detail how much size for each table, you can also use the following query to see.

select 
      sys.objects.name as ''TableName'', sum(reserved_page_count) * 8.0 / 1024 as ''Size (in MB)''
from 
      sys.dm_db_partition_stats, sys.objects 
where 
      sys.dm_db_partition_stats.object_id = sys.objects.object_id
group by sys.objects.name

 
Running those script on the management studio will result:
image_1D2840C3

References

You may want to learn more about SQL Azure tips and tricks, be sure to check out the following posts:

Hope this helps.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*