Thursday, May 1, 2014

HeapTable

Heap Table:   A table which doesn't have a clustered index is called Heap table.

We can describe a 'heap table' let SQL server do a table scan on it while retrieving data, which obviously not good. So try to avoid heap tables in your database to give 100% chances to get the performance.

You can find the heap tables by using following T-SQL statement.

USE [YourDataBaseName]
GO

SELECT SCH.name + '.' + TBL.name AS TableName
    FROM sys.tables AS TBL
    INNER JOIN sys.schemas AS SCH
         ON TBL.schema_id = SCH.schema_id
    INNER JOIN sys.indexes AS IDX
         ON TBL.object_id = IDX.object_id
            AND IDX.type = 0 -- = Heap
    ORDER BY TableName   

No comments:

Post a Comment