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
Advertisements

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

  1. Jason

    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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s