Query to check index on a table

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

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

10条回答
  •  执念已碎
    2020-12-13 06:22

    First you check your table id (aka object_id)

    SELECT * FROM sys.objects WHERE type = 'U' ORDER BY name
    

    then you can get the column's names. For example assuming you obtained from previous query the number 4 as object_id

    SELECT c.name
    FROM sys.index_columns ic
    INNER JOIN sys.columns c ON  c.column_id = ic.column_id
    WHERE ic.object_id = 4 
    AND c.object_id = 4
    

提交回复
热议问题