• This is a very good question, thank you Dave. The key here is the index_id: if the table has a clustered index then there will be a record in the stats view with index_id = 1. If the table is a heap then it will have index_id = 0. There is no way to have both index_id 0 and 1, so index_id < 2 or like you have it index_id = 0 or index_id = 1 should suffice. Grouping is important because it possible to have partitioned table.

    Oleg