Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

elenco di tabelle senza indici in sql 2008

Questo dovrebbe coprire ciò che stai cercando. ovvero tabelle che sono heap (nessun indice cluster) e non hanno indici non cluster. Utilizza il nuovo sys. oggetti tabella utilizzati nel 2005/2008.

inoltre, probabilmente vorrai cercare tabelle che hanno un indice cluster, ma non hanno indici non cluster (questa è la seconda parte dell'istruzione che ho lasciato commentata.

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))