Search This Blog

Tuesday, August 14, 2007

How to calculate Table Size

Calculate space used by a Single row of the table.
1) First is we need to add the storage requirementts for each of the data type present in the table
2) Add null bitmap by the formula below
null_bitmap = 2 + ((number of columns + 7)/8)
3) Next is variable length columns like varchar,for which use the below formula:
variable_data_size = 2 + (number of variable columns * 2) + max_varchar_size
4) And calculate the sum of fixed data size like char,int,bigint,numeric,datetime
5) So now the total row size would be sum of all these values
Row_Size = Null_Bitmap + Variable_data_size + Fixed_Data_Size + Row_Header(4 bytes)

Now to find total number of rows in a page.Each page size is 8192 bytes with the page header,leaving that we can have 8096 bytes of data.
Therefore number of Rows would be
8096 / (Rowsize+2)

Total Number of Pages a particular table has can be found by the following formula
Number of Pages = Number of Rows in Table/Number of Rows per page

No comments: