Is my table is stored as heap or b-tree?

Posted on

Question :

I have a SQL Server 2005 database. It’s .MDF & .LDF can be downloaded at

Now I want to know whether two table are stored as heap or b-tree(linked list), so I run the following commands:


    sys.objects, sys.partitions, sys.system_internals_allocation_units
    (sys.partitions.object_id = sys.objects.object_id) and   
    (sys.system_internals_allocation_units.container_id = sys.partitions.partition_id) and
    ((name = 'cardfa') or (name = 'pcspkc'));

Where ‘cardfa’ and ‘pcspkc’ are the two user tables I want to investigate.

The result is below:

table result

Based on, since both table’s index_id is 1, they are all stored as b-tree(the data pages in the leaf level is in linked list).

However, in the result table, the first row has first_page value (filenum, pagenum) = (1, 0x6F2A8) which is an invalid pointer.

The second row has first_page value (filenum, pagenum) = (1, 0x5941) = (1, 22849).

After I using the following commands:

DBCC page(CR_YPLS8_NEW_QB, 1, 22849, 3);

I get the following result:

dbcc page result

After checking each column in each slot, I find the data is completely different from the actual data stored in ‘cardfa’ table. So the first_page for the second row is also invalid.

And I then find the ‘cardfa’ table is actually stored in heap and can be referenced by first_iam_page instead of first_page, which is inconsistent with the search result. Why?


Answer :

If your table has a clustered index it is stored as a b-tree otherwise it is a heap.

Leave a Reply

Your email address will not be published. Required fields are marked *