SQL Server 2005 sp2 - Used following query to build dbcc showcontig commands:

SELECT 'dbcc showcontig (' +
CONVERT(varchar(20),i.id) + ',' + -- table id
CONVERT(varchar(20),i.indid) + ') -- ' + -- index id
object_name(i.id) + '.' + -- table name
i.name -- index name
from sysobjects o
inner join sysindexes i
on (o.id = i.id)
where o.type = 'U'
and i.id = object_id(o.name)
ORDER BY
object_name(i.id), i.indid

But it builds invalid commands (ie Cannot find a row in the system catalog with the index ID 3 for table "BPTNXT")

I have one index on the BPTNXT table but when I query sysindexes it looks to have 2 indexes ... Could indexes get deleted without sysindexes getting updated or did I just not build my commands properly?


2121058592 0 0xC23100000100 0 0x703300000100 64 0 1 3 6 6 325 876984 0 0 68 15 0 0 0 0xEA3200000100 0 0 0 NULL NULL NULL 8000 325
2121058592 2 0x861300000100 2 0x861300000100 15 3 1 1 2 2 325 0 0 0 19 15 0 0 0 0xA21300000100 0 0 0 NULL BPTNXT_ID01 NULL 8000 325
2121058592 8388704 NULL 3 NULL 0 1 0 0 0 0 0 0 0 0 0 NULL 0 0 0 NULL 0 0 0 NULL _WA_Sys_00000001_7E6CC920 NULL 8000 0