What's the best way to store the days of the week an event takes place on in a relational database?

前端 未结 6 1463
独厮守ぢ
独厮守ぢ 2020-12-23 11:47

We\'re writing a records management product for schools and one of the requirements is the ability to manage course schedules. I haven\'t looked at the code for how we deal

6条回答
  •  既然无缘
    2020-12-23 11:59

    If performance is an issue I would recommend a cleaner varation of #3.

    Link your course to a "schedule" table.

    Which is in turn linked to a days_in_schedule table.

    The days_in_schedule table has columns the schedule_name, and the date in_schedule_day. With a row for each valid day in that schedule.

    You need some time opr some clever program to populate the table but once this is done the flexibility is worth it.

    You can cope not only with "course on Fridays only", but also "first semester only", "lab closed for refurbishment in third semester" and "Canadian branch has differnet holiday schedule".

    Other possible queries are "Whats the end date of 20 day course starting 1st April", which "schedules clash most". If you are really good at SQL you can ask "what possible days are open in course xxx to a student who is already booked for course yyy" -- which I have the feeling is the real puprose of your proposed system.

提交回复
热议问题