• The query provided to detect heaps will also return table valued functions. The query below will return only user tables that are heaps.

    SELECT

    OBJECT_SCHEMA_NAME(i.object_id) AS SchemaName

    ,OBJECT_NAME(i.object_id) AS TableName

    ,i.*

    FROM sys.indexes i

    INNER JOIN sys.objects o ON i.object_id = o.object_id

    WHERE i.index_id = 0

    AND o.type = 'U'