Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

Check if an index exists in SQL Server

$
0
0
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


Viewing all articles
Browse latest Browse all 265

Trending Articles