sql 2008中没有索引的表的列表

Raj*_*ore 9 t-sql sql-server sql-server-2008

如何在SQL 2008数据库中列出没有索引的表?

编辑
我想要Schema名称和Table名称.

Nic*_*ias 10

这应该包括你要找的东西.即堆(没有聚簇索引)并且没有任何非聚集索引的表.它使用新的sys.2005/2008年使用的表格对象.

此外,您可能希望查找具有聚簇索引但没有非聚簇索引的表(这是我已经注释掉的语句的第2部分).

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))  
Run Code Online (Sandbox Code Playgroud)


小智 7

这是一个例子:

select SCHEMA_NAME(schema_id), name from sys.tables 
where OBJECTPROPERTY(object_id, 'IsIndexed')= 0
Run Code Online (Sandbox Code Playgroud)