How to find largest objects in a SQL Server database?

前端 未结 7 1360
说谎
说谎 2020-12-22 15:00

How would I go about finding the largest objects in a SQL Server database? First, by determining which tables (and related indices) are the largest and then determining whi

相关标签:
7条回答
  • 2020-12-22 15:37

    I've found this query also very helpful in SqlServerCentral, here is the link to original post

    Sql Server largest tables

      select name=object_schema_name(object_id) + '.' + object_name(object_id)
    , rows=sum(case when index_id < 2 then row_count else 0 end)
    , reserved_kb=8*sum(reserved_page_count)
    , data_kb=8*sum( case 
         when index_id<2 then in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count 
         else lob_used_page_count + row_overflow_used_page_count 
        end )
    , index_kb=8*(sum(used_page_count) 
        - sum( case 
               when index_id<2 then in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count 
            else lob_used_page_count + row_overflow_used_page_count 
            end )
         )    
    , unused_kb=8*sum(reserved_page_count-used_page_count)
    from sys.dm_db_partition_stats
    where object_id > 1024
    group by object_id
    order by 
    rows desc   
    

    In my database they gave different results between this query and the 1st answer.

    Hope somebody finds useful

    0 讨论(0)
提交回复
热议问题