Skip to content
Advertisement

How to structure the database to avoid duplicates in a table

I am doing this exercise where I have to build an sql database (MySql) to store information on private lessons offered by teachers. These are the rules:

  • There is just one predifined week with slot times from Monday to Friday (15-19)
  • Each teacher can teach 1 or more courses
  • Each course can be teached by multiple teachers
  • One user can book just one lesson in a selected hour
  • One teacher can book just one lesson in a selected hour

This is how I implemented it:

This solution causes me two problems, or at least they are the ones I identified:

  1. I can have the same User booked with different Teacher and different Course at the same day and hour
  2. I can have the same User booked with the same Teacher at the same day and hour but with different Course

Here is an example:

What I want to obtain is a table where the rules indicated above are respected, but I can’t figure out how to implement it.

Advertisement

Answer

Sort-out the logical design first, then go into details.

Note:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement