Script to find out Heap Table/Table without clustered Index


Heap Table: Table without a clustered index is called Heap Table. You can find out the Heap Table by querying the sys.indexes or sys.partitions against the index_id column.

select OBJECT_NAME(object_id),* 
from sys.indexes where index_id = 0

Select OBJECT_NAME(object_id),*  
from sys.partitions where index_id = 0

1 thought on “Script to find out Heap Table/Table without clustered Index

  1. Jason's avatarJason

    select
    case when o.id in
    (select id from sysobjects where xtype=’U’ and id not in
    (select parent_obj from sysobjects where xtype=’PK’))
    then ‘HEAP’ else ‘PKI’ end as CLIHEAP
    , o.name ,
    (select max(rows) from sys.partitions as p where p.object_id = o.id) as rows
    from sysobjects as o
    where o.xtype=’U’ and
    case when o.id in
    (select id from sysobjects where xtype=’U’ and id not in
    (select parent_obj from sysobjects where xtype=’PK’))
    then ‘HEAP’ else ‘PKI’ end =’HEAP’
    order by rows desc

    Reply

Thanks for the comment, will get back to you soon... Jugal Shah