Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with a Index on sql server

New Here ,
Oct 22, 2011 Oct 22, 2011

I have a table named AVAILABILITY

ID - IDHOTEL - IDROOM - DATE_FROM - DATE_TO

for each room a hotel insert a period (from - to) when the room in booked

Considering this query

select id, date_from, date_to from AVAILABILITY

where IDHOTEL = #idhotel#

   and IDROOM = #idroom#

   and DATE_TO >= #dateadd("d",-1,now())#

order by DATE_FROM

Could you suggest me a index to create on the table ?

TOPICS
Database access
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2011 Oct 22, 2011

What are the existing indexes?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 23, 2011 Oct 23, 2011

Actually I have these:

unique clustered index idhotel, idroom, date_from, date_to

non clustered index ID

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2011 Oct 24, 2011

Why do you think you need another one?  Is your query slow?  Using cfqueryparam will speed it up.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2011 Oct 24, 2011

The query isn't slow, but actually database in pretty empty. I want to be sure that it is the best index I could choose.

Could you give me, please, a hint how you would use cfqueryparam in the query? Sorry, I'm not so good in it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 25, 2011 Oct 25, 2011
LATEST

Depending on how many rows are in there, you may find the database engine doesn't actually bother using the index at all, it's not until you have thousands of rows it really starts to make a difference.

Weigh that up with the amount it'll slow down inserts, and you might find it detrimental to create an index. Definitely put in queryparams though, there's never an excuse for not doing that and as Dan says that'll speed things up a bit.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources