我试图压缩我的数据库中最大的表.我将通过运行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;