Search code examples
sql-server

How do you check if a certain index exists in a table?


Something like this:

SELECT
* 
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
WHERE CONSTRAINT_NAME ='FK_TreeNodesBinaryAssets_BinaryAssets'
and TABLE_NAME = 'TreeNodesBinaryAssets'

but for indexes.


Solution

  • You can do it using a straight forward select like this:

    SELECT * 
    FROM sys.indexes 
    WHERE name='YourIndexName' AND object_id = OBJECT_ID('Schema.YourTableName')