What is the best way to store DateTime in SQL Server to provide maximum search speed for large table? The table contains the records, and one row has to contain the date and time.
The searches are like
Value > '2008-1-1' AND Value < '2009-1-1'
or
Value > '2008-1-1' AND Value < '2008-31-1'
etc.
Which is the best? The DateTime with index? The unixstamp in long with index? Multiple int fields like year, month, day ect.? Or something else?
I’d use the smallest datatype that supports what level of datetime accuracy you need.
e.g.
You don’t mention how large a table you are talking. But there are strategies for dealing with improving query performance on top of standard indexing strategy (e.g. partitioning, filtered indices)