sql server - How do you get to limits of 8060 bytes per row and 8000 per (varchar, nvarchar) value? -


comining question "8078 bytes in 8060 b datapage (sql server)?" explained me how derive 8078 bytes of data per page in ms sql server.

if calculate number of bytes per page used data storage (without overhead) of 1 row 1 column of non-indexed fixed-size type record (as per msdn article estimating size of heap), come 8087 bytes (per page).

how to limits of 8060 bytes per row (mentioned in other question's answers) , 8000 bytes per (varchar, nvarchar) without buying , studying 1000+ page books?

i missing in storage allocation: fewer chunks manage, more overhead...

inside storage engine: anatomy of record

this sql server 2005

  • record header
    • 4 bytes long
    • two bytes of record metadata (record type)
    • two bytes pointing forward in record null bitmap
  • fixed length portion of record, containing columns storing data types have fixed lengths (e.g. bigint, char(10), datetime)
  • null bitmap
    • two bytes count of columns in record
    • variable number of bytes store 1 bit per column in record, regardless of whether column nullable or not (this different , simpler sql server 2000 had 1 bit per nullable column only)
    • this allows optimization when reading columns null
  • variable-length column offset array
    • two bytes count of variable-length columns
    • two bytes per variable length column, giving offset end of column value versioning tag
  • this in sql server 2005 , 14-byte structure contains timestamp plus pointer version store in tempdb

so, 1 char(8000)

  • 4 bytes (record header)
  • 8000 fixed length
  • 3 null bitmap
  • 2 bytes count variable-length
  • 14 timestamp

however, if had 40 varchar(200) columns

  • 4 bytes (record header)
  • 0 fixed length
  • 6 null bitmap
  • 2 bytes count variable-length
  • 202 x 40 = 8080
  • 14 timestamp

total = 8080 + 4 + 6 + 2 + 14 = 8106. wtf? warning when created table

i not hung on it: information has no practical day day value


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -