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:
USER(Name, Surname, Email (PK), Password)
TEACHER(Name, Surname, Email (PK), Password)
COURSE(Title (PK))
SLOTTIME(Day (PK), Hour (PK))
TEACHES(EmailTeacher, TitleCourse) all attributes are PK, FK(EmailTeacher -> Teacher, TitleCourse -> Course)
BOOKING(EmailUser, EmailTeacher, TitleCourse, Day, Hour) all attributes are PK, FK((EmailUser -> User),
(EmailTeacher, TitleCourse -> Teaches), (Day, Hour -> SlotTime))
This solution causes me two problems, or at least they are the ones I identified:
- I can have the same User booked with different Teacher and different Course at the same day and hour
- 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:
BOOKING('raul@gmail.com', 'michael@gmail.com', 'Database I', 'Monday', 16) // FIRST INSERT
BOOKING('raul@gmail.com', 'anthony@gmail.com', 'Algorithms', 'Monday', 16) // DIFFERENT TEACHER AND COURSE
BOOKING('raul@gmail.com', 'michael@gmail.com', 'Database II', 'Monday', 16) // SAME TEACHER AND DIFFERENT COURSE
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.