我正在尝试压缩数据库中最大的表。我将通过运行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
对我所有的桌子等等。
我在寻找相同的东西,但返回的是页面计数。
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;