Help with a Index on MS sql server

Posted on 2011-10-22
Last Modified: 2012-08-14
I have a table named AVAILABILITY
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 ?
Question by:Giambattista
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    you need a covering index in this order  idhotel,idroom, date_to, ..
    LVL 23

    Accepted Solution

    I'd recommend using two indexes: one unique clustered index including , in the following order:  IDHOTEL - IDROOM - DATE_FROM - DATE_TO and a non clustered index on ID

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Via a live example, show how to shrink a transaction log file down to a reasonable size.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now