سؤال

في MSSQL2005 عندما أرغب في الحصول على حجم الجدول في MBS ، أستخدم exec sp_spaceused 'table'.

هل هناك أي طريقة للحصول على مساحة تستخدمها جدول معين في SQL Azure باستخدام بعض الاستعلام أو API؟

هل كانت مفيدة؟

المحلول

من ريان دنhttp://dunnry.com/blog/calculatingTheSizeOfyourSqLazlazuredatabase.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

أول واحد سوف يمنحك حجم قاعدة البيانات الخاصة بك في MB والثاني سيفعل نفس الشيء ، ولكن قم بتقسيمه لكل كائن في قاعدة البيانات الخاصة بك التي تم طلبها من قبل الأكبر إلى الأصغر.

نصائح أخرى

فيما يلي استعلام يمنحك حسب الجدول الحجم الإجمالي ، وعدد الصفوف والبايت لكل صف:

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

وهنا استعلام هو نفسه على النحو الوارد أعلاه ولكنه يكسره عن طريق الفهرس:

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

بهذه الطريقة يمكنك الحصول على أكبر في الأعلى:

 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

مصدر

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top