我正在尝试压缩数据库中最大的表。我将通过运行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
以及所有我的桌子等等。
我正在寻找相同的东西,但却改回了页数。
答案 0 :(得分:12)
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;