Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list of tables without indexes in sql 2008

How do I list tables without indexes in my SQL 2008 database?

Edit
I want the Schema name and the Table name.

like image 946
Raj More Avatar asked Sep 02 '09 19:09

Raj More


People also ask

Can we have a table without index?

A table without a clustered index is called a heap. With a heap, the data is not ordered by an index, so data is not stored in any particular order.

Which of the listed is a table without a clustered index?

A heap is a table without a clustered index.

How do I find missing indexes?

To determine which missing index groups a particular missing index is part of, you can query the sys. dm_db_missing_index_groups dynamic management view by equijoining it with sys. dm_db_missing_index_details based on the index_handle column.


2 Answers

This should cover what your looking for. i.e. tables that are heaps (no clustered index) and do not have any non-clustered indexes. It uses the new sys. table objects used in 2005/2008.

in addition, you probably want to look for tables that do have a clustered index, but have no nonclustered indexes (this is the 2nd part of the statement which I've left commented out.

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))  
like image 199
Nick Kavadias Avatar answered Oct 18 '22 15:10

Nick Kavadias


Here's an example:

select SCHEMA_NAME(schema_id), name from sys.tables 
where OBJECTPROPERTY(object_id, 'IsIndexed')= 0
like image 25
nausea Avatar answered Oct 18 '22 13:10

nausea