这个架构应该足以让你开始
VISITORS
id
name
... other atomic data
RESOURCES
id
name
... other atomic data
RESERVATIONS
id
visitor
resource
fromdate
tilldate
因此,如果我想在 11 月 19 日 10:00 到 12:00 预订 200 号房间,reservations 表中会有一条记录,其中 'visitor' 字段指向我的visitors 表中的条目,'resource' 字段指向 resources 表中房间 200 的条目,'fromdate' 将等于 19-11 的 10:00 -2012 和 'tilldate' 将等于 '12:00 19-11-2012'。
您可以编写查询来显示在特定日期/时间保留了哪些资源,例如
select resources.name, visitors.name
from resources inner join reservations on resources.id = reservations.resource
inner join visitors on reservations.visitor = visitors.id
where reservations.fromdate <= "2012-11-19 06:00"
and reservations.tilldate >= "2012-11-19 23:59"
以及显示在给定时间哪些资源空闲的查询
select resources.name
from resources
where not exists (select 1 from reservations
where reservations.resource = resources.id
and reservations.fromdate >= "2012-11-19 10:00"
and reservations.tilldate <= "2012-11-19 12:00")
如果有人说“我每周三都来”,您的应用程序必须足够聪明,可以根据所需的资源、日期和时间在“预订”表中插入几行。
另外,请参阅此问题:Database Tables for Reservation site