7

我正在尝试压缩数据库中最大的表。我将通过运行 SP_ForEachDB 存储过程来做到这一点。但是我不知道如何查看总页数。我可以使用此查询获取行数...

USE DEVELOP04_HiltonUS

GO

SELECT 
    [TableName] = so.name, 
    [RowCount] = MAX(si.rows) 
FROM 
    sysobjects so, 
    sysindexes si 
WHERE 
    so.xtype = 'U' 
    AND 
    si.id = OBJECT_ID(so.name) 
GROUP BY 
    so.name 
ORDER BY 
    2 DESC

返回:

            TABLE NAME   ROW COUNT
           PlannedShift  38268660
        BudgetStaffStat  19353104
          BudgetKBIStat  14142631
EmployeeShiftAdjustment  13493745
            Requirement  11020921
     EmployeeShiftError  6857235
      JobclassLaborData  5638692

等等我所有的桌子。

我正在寻找相同的东西,但返回页数。

4

1 回答 1

14
SELECT  OBJECT_SCHEMA_NAME(s.object_id) schema_name,
        OBJECT_NAME(s.object_id) table_name,
        SUM(s.used_page_count) used_pages,
        SUM(s.reserved_page_count) reserved_pages
FROM    sys.dm_db_partition_stats s
JOIN    sys.tables t
        ON s.object_id = t.object_id
GROUP BY s.object_id
ORDER BY schema_name,
        table_name;
于 2012-10-13T02:59:44.713 回答