Many times we come across the scenario where we need to some code based on whether an index exists or not.
The following query may help you to check an index is exists in a particular table or not. Suppose we have a table like dbo.Table1 and it has index idx_Index and in some scenario, we need to check idx_Index exists or not.
System.index catalog view records for each Clustered and Non-Clustered indexes. We can execute the following query to find out a particular index exists or not in a particular table
IFEXISTS ( SELECT 1 FROMsys.indexes WHEREname='idx_Index'ANDobject_id=OBJECT_ID('dbo.Table1') ) BEGIN PRINT'Index is Exists' END |