query for identifying long rows
Is there a query that can help identify tables whos rows potentially are longer than 8060 bytes in MSSQL 2008? I understand that this is the maximum size of a开发者_运维知识库 data row.
eg.
create table a (
a varchar(4000),
b varchar(4000),
c varchar(4000)
)
A quick and dirty one.
SELECT OBJECT_NAME(object_id),SUM(max_length)
FROM sys.columns
WHERE is_computed=0 and OBJECTPROPERTY(object_id,'IsUserTable')=1
GROUP BY object_id
HAVING SUM(max_length) > 8060 or MIN(max_length)=-1 /*MAX datatype*/
Dropped and altered columns can still consume wasted space. This is visible through sys.system_internals_partition_columns
You might be better off looking at sys.dm_db_partition_stats
to determine which objects actually have off row pages allocated.
精彩评论