Take the 2-minute tour ×

I have a nonclustered index (called NCIDX1) on col1, col2 of a table. I included col3, col4, col5, col6 as included columns in this order.

If I run the following query:

     col3 = something
     col4 = something
     col5 = something

Is it any different than running:

     col3,col2 ,col4
     col1 = something
     col5 = something


What I am trying to say is, when we create a covering index like the above, and we change the order in which we are accessing data, will it still take advantage of this covering index?

Thanks in advance

share|improve this question

migrated from serverfault.com Mar 28 '11 at 0:44

This question came from our site for system and network administrators.

1 Answer 1

up vote 7 down vote accepted

Generally, an index should be on

(equalitycol1, equalitycol2, ..., nonequalitycol1, , nonequalitycol2, ...)
(outputonlycol1, outputonlycol2, ...)

Simply (ignoring ranges) this breaks down into

  • equalitycol: WHERE equalitycol = something. Most selective first. SARGable. Seeks.
  • nonequalitycol: WHERE nonequalitycol <> something. Residual filters
  • outputonlycol: SELECT outputonlycol. No filtering or ordering

ORDER BY and GROUP BY columns will be equality or non-equality columns

In this case...

Query 1 doesn't match the index at all, really, so most likely won't use the index. However, the optimiser may decide it's cheaper to use the index then use other table access such as a table scan or a RID/bookmark lookup.

For query 2 the optimiser may decide to use the index because col1 would be an equality match. And then use the unsorted col5 from the INCLUDE. YMMV, but there is a higher chance.

share|improve this answer
Thanks for the clarification. the order of equality columns (amongst themselves) and non equality columns (amongst themselves)... does it matter? like where equalitycol2='' and equalitycol1='' –  Manjot Mar 28 '11 at 20:28
@Manjot: For the WHERE clause order, no: the optimiser works it out. Two index (col1, col2) and (col2, col1) are different though. Note (col1, col2) will be contained by (col1, col2, col3, col4) though so the first isn't needed. –  gbn Mar 29 '11 at 4:57
Thank you very much. –  Manjot Mar 29 '11 at 20:52

Your Answer


