Skip to main content

SQL Server query to check if a specific table index exists.

use DATABASE_NAME;

if exists (
    select top (1) object_id as index_exists
    from sys.indexes
    where name = N'index_name'
        and object_id = object_id(N'schema_name.table_name')
)
    begin
        print 'Found index "index_name" on "schema_name.table_name".';
    end;
else
    begin
        print 'Did not find index "index_name" on "schema_name.table_name".';
    end;