Sql-server – Good idea to have an index on datetime column

indexsql server

Assuming something like so:

select * from table where DatePart(YEAR, dateColumn) = 2012

Reasonable to have an index on dateColumn?

Edit*

For SQLServer

Best Answer

Adding an index is definitely a good idea for this. However, DATEPART(YEAR, datecolumn) = 2012 isnt' sargable so it will still do a scan of the index.

If you want it to use the index then you will need to do:

WHERE dateColumn >= '1/1/2012' AND dateColumn < '1/1/2013'

Please note the placement of the >= and the < signs to get the correct bounding box.