Jason McKittrick's Blog

Table Column Widths

Just sharing a simple block of code to find the width of a row in a given table based on DDL used to create the table.   This is especially helpful if you are looking to take a table to In-Memory with a row size limitation of 8,000. Just used this for one of my customers this morning.  Thought I would share my code for others to use.

select  sys.objects.[name] as TableName, 
           sys.objects.[object_id] as SQLObjectId, 
           count(sys.columns.[name]) As ColumnCount, 
           sum(sys.columns.max_length) As MaxLength
 from  sys.objects so
 inner join sys.columns sc
on so.object_id = sc.object_id
 where  sys.objects.[name] = INSERT TABLE NAME HERE
 group by  sys.objects.[name], 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.