select a,b,max(c) from myTable
where a>b
group by a,b
my first instinct is to open a clustered index for [a,b,c]
and here is the question :
suppose someone is running another simple select :
select a from myTable.
will the [a] column will be seeked throught the [a,b,c] index? or it wont use index at all…? (my guess it will use the [a,b,c] index)
but i guess it wont be fast as a single [a] index…
so what should i do ?
create [a,b,c] index
or
create [a,b,c] + [a] index
Your first thought is correct. The query:
will be able to use the
(a,b,c)index effectively. No need to add the(a)index.As to whether this index should be clustered or not, that’s a whole other discussion. Since SQL-Server allows only one clustered index per table, the choice should be made wisely. See the MSDN articles: Clustered Index Design Guidelines and Creating Clustered Indexes.