English 中文(简体)
SQL Azure table size
原标题:

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

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

最佳回答

From Ryan Dunn http://dunnry.com/blog/CalculatingTheSizeOfYourSQLAzureDatabase.aspx

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

The first one will give you the size of your database in MB and the second one will do the same, but break it out for each object in your database ordered by largest to smallest.

问题回答

Here is a query which will give you by table the total size, number of rows and bytes per row:

select 
    o.name, 
    max(s.row_count) AS  Rows ,
    sum(s.reserved_page_count) * 8.0 / (1024 * 1024) as  GB ,
    (8 * 1024 * sum(s.reserved_page_count)) / (max(s.row_count)) as  Bytes/Row 
from sys.dm_db_partition_stats s, sys.objects o
where o.object_id = s.object_id
group by o.name
having max(s.row_count) > 0
order by GB desc

And here is a query which is the same as above but breaks it down by index:

select  
    o.Name,
    i.Name,
    max(s.row_count) AS  Rows ,
    sum(s.reserved_page_count) * 8.0 / (1024 * 1024) as  GB ,
    (8 * 1024* sum(s.reserved_page_count)) / max(s.row_count) as  Bytes/Row 
from 
    sys.dm_db_partition_stats s, 
    sys.indexes i, 
    sys.objects o
where 
    s.object_id = i.object_id
    and s.index_id = i.index_id
    and s.index_id >0
    and i.object_id = o.object_id
group by i.Name, o.Name
having SUM(s.row_count) > 0
order by GB desc

This way you can have the bigger on top:

 SELECT  sys.objects.name,
            SUM(row_count) AS  Row Count ,
            SUM(reserved_page_count) * 8.0 / 1024 AS  Table Size (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
    ORDER BY [Table Size (MB)] DESC

Source





相关问题
CGImage create thumbnail image with desired size

I want to create the thumbnail using the CG. It creates the thumbnails. Here i want to have the thumbnail with the size 1024 (with aspect ratio.) Is it possible to get the desired size thumbnail ...

How to get the size of an image in bytes with Delphi?

my app has 3 controls: TThumbnailList (image viewer from TMS components), TImage, and TLabel. I wish that when I drag an image from TThumbnailList to TImage, and drop it, the TLabel object shows the ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

Size of reference of an class in JAVA

What is the size of reference of a class in Java? Is it constant for a particular JVM and OS irrespective of the class for which the reference is made. Class A Class B Class C A a; B b; C c; Are ...

MPLAB IDE data type sizes

In MPLAB IDE what is the sizes of data types (int, unsigned int, float, unsigned float, char...)?

热门标签