General concepts
There are five kinds of pages in MS SQL 6.5:
In this article I want to tell you about data page structure in
MS SQL 6.5. The size of the data page in MS SQL 6.5 is 2Kb, i.e.
2048 bytes. Every data page consists of three part:
See Figure 1:
Figure 1. General data page structure
This is the description of the page header:
pageno - is a logical page number nextpg - next logical page number prevpg - previous logical page number objid - id of the table timestamp - internal identifier nextrno - next row number, that will be written on this page level - the index level indid - id of the index freeoff - pointer to the free space at the end of the page minlen - minimum rows length for this data page
Offset table contains two bytes for each row on the data page.
MS SQL 6.5 uses the offset table to find the address of row.
Every cell of the offset table contains the address of the row
on the data page.
When you delete record, MS SQL 6.5 writes in the appropriate
cell the zero value, deletes row, moves other rows to avoid
free space between them and sets the new value into freeoff
field of the page header. All rows are stored continuously
on the data page.
When you insert new record, MS SQL 6.5 scans the offset table
from the end. If there is cell with zero value in it, then
offset of the new row will be inserted into this cell. If there
is no cell with zero values in it, then new cell will be added
in the offset table, new value will be written into freeoff field
of the page header and the nextrno field of the page header will
be increased by 1.
You can use the following command to view the data page structure
(this command is not very good documented in SQL Server Books Online):
|
PARAMETERS:
Dbid or dbname - Enter either the dbid or the name of the database
in question.Pagenum - Enter the page number of the SQL Server page that is to
be examined.Print option - (Optional) Print option can be either 0, 1, or 2.
0 - (Default) This option causes DBCC PAGE to print
out only the page header information.
1 - This option causes DBCC PAGE to print out the
page header information, each row of information
from the page, and the page's offset table. Each
of the rows printed out will be separated from
each other.
2 - This option is the same as option 1, except it
prints the page rows as a single block of
information rather than separating the
individual rows. The offset and header will also
be displayed.Cache - (Optional) This parameter allows either a 1 or a 0 to be
entered.
0 - This option causes DBCC PAGE to retrieve the page
number from disk rather than checking to see if it is
in cache.
1 - (Default) This option takes the page from cache if it
is in cache rather than getting it from disk only.Logical - (Optional) This parameter is for use if the page number
that is to be retrieved is a virtual page rather then a
logical page. It can be either 0 or 1.0 - If the page is to be a virtual page number.
1 - (Default) If the page is the logical page number.
Examples
In this examples I also use trace flag 3604.
Trace flag 3604 sends trace output to the client. This trace
flag is used only when setting trace flags with DBCC TRACEON
and DBCC TRACEOFF.
Discounts data page structure
In this example one data page is output from the table discounts,
database pubs.
|
This is the result from my computer:
|
See Figure 2:
Figure 2. Discounts data page structure
After delete
When you delete record, MS SQL 6.5 writes in the appropriate
cell the zero value, deletes row, moves other rows to avoid
free space between them and sets the new value into freeoff
field of the page header. All rows are stored continuously
on the data page.
|
This is the result from my computer:
|
See Figure 3:
Figure 3. After delete
After insert
When you insert new record, MS SQL 6.5 scans the offset table
from the end. If there is cell with zero value in it, then
offset of the new row will be inserted into this cell. If there
is no cell with zero values in it, then new cell will be added
in the offset table, new value will be written into freeoff field
of the page header and the nextrno field of the page header will
be increased by 1.
|
This is the result from my computer:
|
See Figure 4:
Figure 4. After insert
Literature
1. SQL Server Books Online.
2. INFO: Description of DBCC PAGE Command
http://support.microsoft.com/support/kb/articles/Q83/0/65.ASP