8078 bytes in 8060 B datapage (SQL Server)?

混江龙づ霸主 提交于 2019-12-23 13:17:45

问题


It is written everywhere that data in SQL Server is written in pages of 8K (8192 B) each with 8060 bytes for data and the rest is overhead (system info).

Though, the recent article [1] gives code example illustrating, as I understood, that 8078 bytes of data fit into a page.

What do I miss in understanding 8,060 B per per page?

I verified the code on x86 SQL Server 2008 R2...


Update:

Did I see an answer telling about follow-ups to [1]? I pity that I did not mark that as helpful (to me) and comment immediately... I just wanted to investigate more myself before responding...


Update2:

I posted subquestion [2]

[1]
How table design can impact your SQL Server performance?
http://sqlserver-training.com/how-table-design-can-impact-your-sql-server-performance/-

[2]
How to come to limits of 8060 bytes per row and 8000 per (varchar, nvarchar)?
How do you get to limits of 8060 bytes per row and 8000 per (varchar, nvarchar) value?


回答1:


Long answer short, the limit is 8060 bytes per row, but 8096 bytes per page. The rows in the article you linked have a row size of ~4000 bytes, so they are well under the limit per row. However, that does not answer the question of how many such rows fit on a page.

See "Estimating the size of a heap" in Books Online:

http://msdn.microsoft.com/en-us/library/ms189124.aspx

If you do the calculation for the tables in the article, you'll see that the first table has a physical row size of 4048 bytes, which is exaclty half the 8096 limit for a page.




回答2:


  • The maximum row size is 8060 bytes
  • In this case, there are two rows each of 4039 bytes


来源:https://stackoverflow.com/questions/3778721/8078-bytes-in-8060-b-datapage-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!