SQL Azure table size

前端 未结 3 772
别那么骄傲
别那么骄傲 2021-01-29 23:52

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 q

3条回答
  •  长情又很酷
    2021-01-30 00:18

    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
    

提交回复
热议问题