I have two tables sessions and schedules, and I want to add a new table destinations.
The destinations table can be related to both tables, but only ONE destination can be related to a session or schedule:
- N destinations -> ONE session
- N destinations -> ONE schedule
Solution 1:
Create a destination table with two foreign keys (id_session and id_schedule) and only populate one for each destination.
Solution 2
I create destinations, schedule_destinations and sessions_destinations with the following relations:
- 1 destinations -> 1 schedule_destinations (id_destination [UNIQUE], id_schedule) -> N schedules
- 1 destinations -> 1 session_destinations (id_destination [UNIQUE], id_session) -> N sessions
Thanks!
To make your structure consistent with your business rules (one relationship relates with session or schedule), I would create 2 tables:
schedule_destinationswith foreign key toschedule.session_destinationwith foreign key tosessions.And do not create third table
destinations.In the solution, you will have different sets of different destinations. Hence, you will not have one destination to session and schedule at the same time.
SelectsI would do from both tables if you need both types destinations in the same result.