views:

98

answers:

1

I'm preparing to the SQL Server exam (70-431). I have the book from Sybex "SQL Server 2005 - Implementation and Maintenance". I'm little confused about estimating a size of a table.

In the 2nd chapter there is explained how to do this:

  1. Count the row size from the formula: Row_Size = Fixed_Data_Size + Variable_Data_Size + Null_Bitmap + Row_Header.
    • Fixed_Data_Size is a sum of all sizes of fixed length columns (simple sum)
    • Variable_Data_Size = 2 + (num_variable_columns × 2) + max_varchar_size, num_variable_columns - number of columnt with variable length, max_varchar_size - maximum size of varchar column
    • null_bitmap = 2 + ((number of columns + 7) ÷ 8) (rounded down)
    • Row_header always equals 4.
  2. Calculating rows per page from the formula: Rows_Per_Page = 8096 ÷ (Row_Size + 2) (rounded down)
  3. Estimating the number of rows in the table. Let's say that table has 1,000 rows.
  4. Calculating the number of pages needed: No_Of_Pages = 1,000 / Rows_Per_Page (rounded up)
  5. Total size: Total_Size = No_Of_Pages * 8,192, where 8,192 is the size of one page.

So everything is perfectly clear for me. I made one example and checked with the answers in the book that my calculations are correct. But there is one question which confuses me.

The question is: we have a table with the following schema:

Name       Datatype
-------------------
ID         Int
VendorID   Int
BalanceDue Money
DateDue    Datetime

It is expected that in this table there will be about 5,000 rows. Question (literaly): "How much space will the Receivables table take?"

So my answer is simple:

null_bitmap = 2 + ((4+7) / 8) = 3.375 = 3 (rounded)
fixed_datasize =  4 + 4 + 8 + 8 = 24
variable_datasize = 0
row_header = 4 (always)

row_size = 3 + 24 + 0 + 4 = 31

But in the answer they omit row_header and they don't add 4. Is it a mistake in the book or row_header is added only in some cases (which are not mentioned in the book)? I was thinking that maybe row_header is added only if there are variable-length fields in the table, but there is another exercise in which there are not variable-length fields and row_header is added. I would appreciate if someone explains me that. Thanks.

+3  A: 

Inside the Storage Engine: Anatomy of a record says all records have a record header:

The record structure is as follows:

  • record header
    • 4 bytes long
    • two bytes of record metadata (record type)
    • two bytes pointing forward in the record to the NULL bitmap
Remus Rusanu