Query to check index on a table

后端 未结 10 1714
南方客
南方客 2020-12-13 06:06

I need a query to see if a table already has any indexes on it.

10条回答
  •  Happy的楠姐
    2020-12-13 06:23

    On SQL Server, this will list all the indexes for a specified table:

    select * from sys.indexes
    where object_id = (select object_id from sys.objects where name = 'MYTABLE')
    

    This query will list all tables without an index:

    SELECT name
    FROM sys.tables 
    WHERE OBJECTPROPERTY(object_id,'IsIndexed') = 0
    

    And this is an interesting MSDN FAQ on a related subject:
    Querying the SQL Server System Catalog FAQ

提交回复
热议问题