SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


IndexID = 0?


IndexID = 0?

Author
Message
TriggerMe
TriggerMe
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1210 Visits: 328

Ok, I'm confused!

I have a table called CREDITORS. This Table has a Primary Key with a NONCLUSTERED INDEX on CRED_ID. This means that there is only 1 Index on the Table.

If I execute this command; DBCC SHOWCONTIG (CREDITORS)

I get fragmentation info for an IndexID of 0. What is this Index? There is only 1 Index on the Table and it has an IndexID of 2 which happens to be the NONCLUSTERED INDEX in the Primary Key for CRED_ID.

If I execute this command, I get the correct fragmentation info for the Index CREDITORS_PK which is the NONCLUSTERED INDEX in the Primary Key for CRED_ID.

Can someone please explain?




Kindest Regards,



Scott Thornburg
Scott Thornburg
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 Visits: 801

It's a little buried in BOL for DBCC SHOWCONTIG, but Index ID 0 refers to a heap table, i.e., one without a clustered index.

IndexIdID of the index. IndexId is 0 for a heap.


A given table will always have one entry in sysindexes for either IndID = 0 or IndID = 1. Of course, it can have other entries for every non-clustered index as well.


Scott Thornburg





TriggerMe
TriggerMe
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1210 Visits: 328

so therefore, there really is 2 Indexes to this table? 1 for the Heap and 1 for the Primary Key(NONCLUSTERED INDEX)?

Having said that, if the heap Index is fragmented, do you defrag it like you would with a normal Index?




Kindest Regards,



Scott Thornburg
Scott Thornburg
SSC-Addicted
SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)SSC-Addicted (405 reputation)

Group: General Forum Members
Points: 405 Visits: 801

It is not accurate to say that the table has two indexes in this case. Unlike a table with a clustered index (IndID = 1) which is well-ordered based on the index key, a heap table has no logical order. It is simply a conglomeration of data. Your table has just one index -- the non-clustered one you created.

As such, for a heap table there is no concept of defragmenting the table. The standard methods of DBCC INDEXDEFRAG and such do not work.

There can be issues with heap tables, see for example, Kalen Delaney's explanation at http://www.windowsitpro.com/SQLServer/Articles/ArticleID/25198/pg/2/2.html. My understanding is that the only way to compact a heap table is to either reload it (move data out, truncate, move back in ) or to shrink the database itself. I may have missed a method or two here, however.

Scott Thornburg





TriggerMe
TriggerMe
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1210 Visits: 328
I'll have aread of the article however, I'm able to retrieve fragmentation info for the IndexID of 0. I must say, it is very fragmented.


Kindest Regards,



Frank Kalis
Frank Kalis
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8591 Visits: 289

See if this helps:

http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx



--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search