Skip to content
Advertisement

How to search/select a list of composite index values and get the exact matching rows in SQL Server?

I have a list of value pairs that I have to search in a table in SQL Server. the table is something like this:

The columns id and class have an unique composite index that I want to take advantage of. Now I have this list of id-class pairs that I have to get from this table:

I need to select them to UPDATE the value of both rows to any value. Let’s say 1000.

My problem is, how do I select those two rows while taking advantage of the composite index?

I have tried this:

But this returns me the combinations:

and I just want:

this would work:

but this breaks the index. Is there a way to get what I need while taking advantage of the index?

Advertisement

Answer

The follow scripts will take advantage of composite index:

or this:

or this:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement