CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

How Sql Server 2005 bypasses the 8KB row size limitation

Here I talked about row size limitations and using varchar versus nvarchar data in Sql Server.  Now, lets look at what you can do in Sql Server 2005 that allows you to surpase the 8KB row size limit.

Sql Server 2005 still adheres to the 8K page size.  But now, you are allowed to have rows that exceed that limit.  Individual columns still must adhere to 8K limits.  This means you can have a table defined as varchar(5000), varchar(5000), but you cannot have a table defined as varchar(10000).  The same applies with nvarchar, which would be a table with nvarchar(3000), nvarchar(3000), but you’re not allowed nvarchar(5000).  What happens in Sql Server 2005 is that when combinations of varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns exceeds the 8K limit, the column for a record with the largest size is moved to another page in what is called a ROW_OVERFLOW_DATA allocation unit, again like Text and Image data, keeping a 24 byte pointer in the original data page, which is the IN_ROW_DATA allocation unit.

This all happens behind the scenes, but understand the performance consequences of this happening.  When you update a row with data that will cause the row to exceed the 8K limit, part of that row is moved to a new page.  If you update a row that is split between pages and it now fits within the 8K limit, this may cause the split row to be merged back into the original data page, both of which cause performance degredation.  Querying data or performing joins on data that have data allocated in the ROW_OVERFLOW_DATA also slows performance because these records are processed synchronously.  If you were to normalize that data so that the data is split between tables and use a JOIN instead of using rows larger than 8K, this speeds your performance back up because JOINS are asynchronous operations.



Comments

Scott Whigham said:

Good stuff - I had read that back in Beta 1 PDFs but had totally forgot about that... Thanks :)
# December 30, 2005 4:52 PM

Jason Haley said:

# December 31, 2005 8:35 AM

Diego Reyes said:

Hello Ray. Perhaps or Sure you can help me.

I have a small table with 3 columns. One is an Integer, the second is XML and the last one is varchar(20). Until here no problem, many rows have a data length more than 8060 kb in the xml data column. Here is the problem, this column was nullable and i wanted to alter this column to Not Null but send me an error "Cannot create a row of size 8088 which is greater than the allowable maximum of 8060"....

What can i do? Thank you a congratulations about your carer.

reyesdiego@hotmail.com

# May 7, 2007 1:29 PM

Raymond Lewallen said:

Diego,

All you are doing is changing the column from allow nulls to not allow nulls?

# May 30, 2007 5:21 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!