How do I create a multiple-table check constraint?

后端 未结 4 2126
长情又很酷
长情又很酷 2020-11-30 03:57

Please imagine this small database...

Diagram

removed dead ImageShack link - volunteer database diagram

Tables

Volunteer         


        
4条回答
  •  抹茶落季
    2020-11-30 04:43

    What I would do is have an Identity column on the EventVolunteer table that auto-increments, with a unique constraint on the EventId, VolunteerId pair. Use the EventVolunteerId (identity) as the foreign key to the Shift table. This enforces the constraint you'd like fairly simply, whilst normalizing your data somewhat.

    I understand this is not the answer to your general question, however I'd see this as the best solution to your specific problem.

    Edit:

    I should have read the question fully. This solution will prevent one volunteer from doing two shifts at the same event, even if they don't overlap. Perhaps moving the shift start and end times to the EventVolunteer and having the check constraint on times on that table would suffice, though then you have shift data outside the Shift table which does not sound intuitive to me.

提交回复
热议问题