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:
- 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 columnnull_bitmap = 2 + ((number of columns + 7) ÷ 8)
(rounded down)Row_header
always equals4
.
- Calculating rows per page from the formula:
Rows_Per_Page = 8096 ÷ (Row_Size + 2)
(rounded down) - Estimating the number of rows in the table. Let's say that table has 1,000 rows.
- Calculating the number of pages needed:
No_Of_Pages = 1,000 / Rows_Per_Page
(rounded up) - 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.