HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Indexing SQL Server datetime Columns for Performance

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnsindexingsqlforperformanceserverdatetime

Problem

Will adding an index to a datetime column increase performance if a WHERE myDateColumn BETWEEN @startDate and @endDate clause is frequently applied to that datetime column?

If yes, should the index be clustered or non-clustered and why?

Solution

Adding an index will increase performance on SELECT statements, assuming your range of dates is not sufficiently large as to force an index scan as opposed to an index seek. Adding an index will decrease performance on INSERT, UPDATE, and DELETE operations, as this new index will need to be maintained. The clustered/nonclustered question is highly dependent on how many other columns from the table you are including in the SELECT clause.

If this question is more than a homework question, and you have examples you would like to include, it would help my answer to be more complete.

Hope this helps,

Matt

Context

StackExchange Database Administrators Q#25100, answer score: 5

Revisions (0)

No revisions yet.