Home All Groups Group Topic Archive Search About

Indexing datetime field for selecting dates ranges

Author
13 Jan 2006 12:53 AM
Amir
Hi,

I have a table with a smalldatetime field. Some of the queries in my
application are using range searches over that smalldatetime field, such as
selecting all the records within a date range. None of these queries are
selecting records from a specific date/time. They all work on ranges (e.g.
using BETWEEN or operators like >=).
Is there any reason for indexing the smalldatetime field? Could that make
the queries run faster?

Regards,
Amir.

Author
13 Jan 2006 12:06 PM
Tibor Karaszi
Yes, indexes on those columns can be beneficial, just as indexes on any column. You need to make
sure that your query is written in a way so that those indexes can be used
(http://www.karaszi.com/SQLServer/info_datetime.asp), of course. And whether the indexes then *will*
be used is dependent on a lot of factors (the query, the data, selectivity etc).

Show quote
"Amir" <ag***@actcom.co.il> wrote in message news:OCbLcq9FGHA.1032@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> I have a table with a smalldatetime field. Some of the queries in my application are using range
> searches over that smalldatetime field, such as selecting all the records within a date range.
> None of these queries are selecting records from a specific date/time. They all work on ranges
> (e.g. using BETWEEN or operators like >=).
> Is there any reason for indexing the smalldatetime field? Could that make the queries run faster?
>
> Regards,
> Amir.
>
Author
13 Jan 2006 6:13 PM
Amir
Thanks for the explanation!

Kind Regards,
Amir.

Show quote
"Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com> wrote in
message news:uOlH7mDGGHA.1424@TK2MSFTNGP12.phx.gbl...
> Yes, indexes on those columns can be beneficial, just as indexes on any
> column. You need to make sure that your query is written in a way so that
> those indexes can be used
> (http://www.karaszi.com/SQLServer/info_datetime.asp), of course. And
> whether the indexes then *will* be used is dependent on a lot of factors
> (the query, the data, selectivity etc).
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
>
> "Amir" <ag***@actcom.co.il> wrote in message
> news:OCbLcq9FGHA.1032@TK2MSFTNGP15.phx.gbl...
>> Hi,
>>
>> I have a table with a smalldatetime field. Some of the queries in my
>> application are using range searches over that smalldatetime field, such
>> as selecting all the records within a date range. None of these queries
>> are selecting records from a specific date/time. They all work on ranges
>> (e.g. using BETWEEN or operators like >=).
>> Is there any reason for indexing the smalldatetime field? Could that make
>> the queries run faster?
>>
>> Regards,
>> Amir.
>>
>

AddThis Social Bookmark Button