How to manage rooms availability based on days or months occupation

浪子不回头ぞ 提交于 2019-12-02 07:24:43

Keep a list of room reservations which have a starting date and ending date. Don't try to model availability slots or think of your reservation database like a spreadsheet. This will just lead you to pointless complexity. Date ranges are easy to work with.

The most important thing to know is how to detect overlapping date ranges in your queries. This is the basis for testing whether a room is already reserved or whether it is free. Let's say you have a RESERVATION table and you want to find reservations that overlap a given date range: @FromDate and @ToDate. Your WHERE clause for finding overlapping reservations looks like this:

WHERE RESERVATION.start_date < @ToDate 
  AND RESERVATION.end_date > @FromDate

Available rooms won't have conflicts (i.e. WHERE NOT IN...) and unavailable rooms will have a conflict.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!