Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k points)

In mssql2005 when I want to get the size of a table in MBs, I use EXEC sp_spaceused 'table'.

Is there any way to get space used by a particular table in SQL Azure using some query or API?

1 Answer

0 votes
by (16.8k points)

The first one here will provide you with the size of your database in MB.

The second will also do the same, but it will break them out for each of the objects in your DB ordered by largest to smallest.

select    

      sum(reserved_page_count) * 8.0 / 1024 [SizeInMB]

from    

      sys.dm_db_partition_stats

GO

select    

      sys.objects.name, sum(reserved_page_count) * 8.0 / 1024 [SizeInMB]

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

order by sum(reserved_page_count) DESC

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...