sql server - list of tables without indexes in sql 2008

PHOTO EMBED

Wed Jul 20 2022 22:39:22 GMT+0000 (Coordinated Universal Time)

Saved by @dhfinch #sql #sqlserver #dbmaintenance

SELECT 
     schemaname = OBJECT_SCHEMA_NAME(o.object_id)
    ,tablename = o.NAME
FROM sys.objects o
INNER JOIN sys.indexes i ON i.OBJECT_ID = o.OBJECT_ID
-- tables that are heaps without any nonclustered indexes
WHERE (
        o.type = 'U'
        AND o.OBJECT_ID NOT IN (
            SELECT OBJECT_ID
            FROM sys.indexes
            WHERE index_id > 0
            )
        )
        --    OR
        -- table that have a clustered index without any nonclustered indexes
        --(o.type='U' 
        --        AND o.OBJECT_ID NOT IN (
        --    SELECT OBJECT_ID 
        --        FROM sys.indexes 
        --        WHERE index_id>1))  
content_copyCOPY

https://stackoverflow.com/questions/1369551/list-of-tables-without-indexes-in-sql-2008