如何确定表的最大行大小?我正在寻找一个工具或脚本,所以我不必手动添加每个列的大小.
我的目标是生成一个太宽的表格报告,以便我们可以考虑重构它们.我知道我们有几个非常宽,每个8K页面只有1行,但我想找到其余部分.
另一种方法,运行它然后查看MaximumRecordsize
dbcc showcontig ('YourTableNameHere') with tableresults
由于DBCC SHOWCONTIG将被弃用,Microsoft
建议使用sys.dm_db_index_physical_stats.您还可以获得每个索引和其他统计信息的最大行数,最小行数和平均行数:
SELECT * FROM sys.dm_db_index_physical_stats (DB_ID(N'AdventureWorks2014'), OBJECT_ID(N'[sales].[SalesOrderHeader]'), NULL, NULL , 'DETAILED')
输出:
database_id object_id index_id partition_number index_type_desc alloc_unit_type_desc index_depth index_level avg_fragmentation_in_percent fragment_count avg_fragment_size_in_pages page_count avg_page_space_used_in_percent record_count ghost_record_count version_ghost_record_count min_record_size_in_bytes max_record_size_in_bytes avg_record_size_in_bytes forwarded_record_count compressed_page_count ----------- ----------- ----------- ---------------- ------------------------------------------------------------ ------------------------------------------------------------ ----------- ----------- ---------------------------- -------------------- -------------------------- -------------------- ------------------------------ -------------------- -------------------- -------------------------- ------------------------ ------------------------ ------------------------ ---------------------- --------------------- 6 1266103551 1 1 CLUSTERED INDEX IN_ROW_DATA 3 0 0.439882697947214 28 24.3571428571429 682 98.8644304423029 31465 0 0 154 195 171.487 NULL 0 6 1266103551 1 1 CLUSTERED INDEX IN_ROW_DATA 3 1 0 2 1 2 54.7442550037064 682 0 0 11 11 11 NULL 0 6 1266103551 1 1 CLUSTERED INDEX IN_ROW_DATA 3 2 0 1 1 1 0.296515937731653 2 0 0 11 11 11 NULL 0 6 1266103551 2 1 NONCLUSTERED INDEX IN_ROW_DATA 2 0 0 4 25.5 102 99.0670990857425 31465 0 0 24 24 24 NULL 0 6 1266103551 2 1 NONCLUSTERED INDEX IN_ROW_DATA 2 1 0 1 1 1 31.4801087225105 102 0 0 23 23 23 NULL 0 6 1266103551 3 1 NONCLUSTERED INDEX IN_ROW_DATA 2 0 0 3 36.3333333333333 109 99.8363355572029 31465 0 0 26 26 26 NULL 0 6 1266103551 3 1 NONCLUSTERED INDEX IN_ROW_DATA 2 1 0 1 1 1 36.3355572028663 109 0 0 25 25 25 NULL 0 6 1266103551 4 1 NONCLUSTERED INDEX IN_ROW_DATA 2 0 0 2 27.5 55 98.9285025945145 31465 0 0 12 12 12 NULL 0 6 1266103551 4 1 NONCLUSTERED INDEX IN_ROW_DATA 2 1 0 1 1 1 11.527057079318 55 0 0 15 15 15 NULL 0 6 1266103551 5 1 NONCLUSTERED INDEX IN_ROW_DATA 2 0 0 2 27.5 55 98.9285025945145 31465 0 0 12 12 12 NULL 0 6 1266103551 5 1 NONCLUSTERED INDEX IN_ROW_DATA 2 1 0 1 1 1 13.5656041512231 55 0 0 18 18 18 NULL 0
这是我得到的另一个查询,但是像Tomalak一样,它被破坏了,因为它没有考虑诸如可变长度列的开销之类的事情.
SELECT OBJECT_NAME (id) tablename , COUNT (1) nr_columns , SUM (length) maxrowlength FROM syscolumns GROUP BY OBJECT_NAME (id) ORDER BY OBJECT_NAME (id)