Query to check index on a table

后端 未结 10 1707
南方客
南方客 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:41

    check this as well This gives an overview of associated constraints across a database. Please also include facilitating where condition with table name of interest so gives information faster.

       select 
    a.TABLE_CATALOG as DB_name,a.TABLE_SCHEMA as tbl_schema, a.TABLE_NAME as tbl_name,a. CONSTRAINT_NAME as constraint_name,b.CONSTRAINT_TYPE
     from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE a
    join INFORMATION_SCHEMA.TABLE_CONSTRAINTS b on
     a.CONSTRAINT_NAME=b.CONSTRAINT_NAME
    

提交回复
热议问题