1

I have created non clustered index on combination of three columns. Do I need to specify all the three columns in where condition to used non clustered index.

1
  • I don't think so. But in order for that index to be used, the first column must be in the WHERE clause. Commented Sep 11, 2015 at 6:30

2 Answers 2

1

In order to utilize your index you have to use like this.

Index: Ix_threecols(c1,c2,c3)

1. select c1,c2,c3 from table where c1=val
and c2=val and c3=val
2. select c1,c2,c3 from table where c1=val
and c2=val
3. select c1,c2,c3 from table where c1=val

Your left most first column in the index should be used in the where clause. Please don't use (*) in your select since it may lead to index scan.

We have to check the execution plan for more analysis on this.

Sign up to request clarification or add additional context in comments.

2 Comments

what if i use where c1=val or c2 =val
You can use like this but it would be an index scan if you use 'or'
1

The short answer is no.

If at least the first column in the index appears in your where clause, the index can be used. Whether or not it will be used is already up to the optimizer, but assuming you don't have any other indexes on other columns in the where clause, it will probably be used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.