|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Indexing datetime field for selecting dates rangesHi,
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. 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 quoteTibor 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. > 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. >> > |
|||||||||||||||||||||||