Possible Duplicate:
SQL Server Clustered Index – Order of Index Question
I understand that column order in a clustered index is important.
I plan to add a clustered index on 3 columns that are always involved in where clauses -an int, bit and datetimeoffset columns. In addition, the datetimeoffset column stores incremental values.
Would it make sense to have the datetimeoffset column as the first one in the clustered index? Appreciate it.
As Michael mentioned, the column order in your index is directly linked to what you have in your WHERE clause.
To illustrate this point, as a test I created three tables, each with a different column as the first in the clustered index. Then, I populated them with 10,000 rows of data.
Executing the same SQL query across all three tables yields very different performance results:
Statistics are as follows:
First table (Date Column first)
Scan count 1, logical reads 3
CPU time = 0 ms, elapsed time = 0 ms.
Second table (Date Column second)
Scan count 1, logical reads 29
CPU time = 0 ms, elapsed time = 113 ms.
Third table (Date Column third)
Scan count 1, logical reads 29
CPU time = 0 ms, elapsed time = 145 ms.
As you can see, querying on the date on the table where the date column is ordered first in the clustered index clearly produces much better results.