Check if an index exists in SQL Server

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 scenarios, 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.


IF EXISTS
(
  SELECT 1 FROM sys.indexes
  WHERE name='idx_Index' AND object_id = OBJECT_ID('dbo.Table1')
)
BEGIN
     PRINT 'Index is Exists'
END

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...