Search code examples
databasedatabase-designmodelrelational-databaserelational-model

Solving ternary to create the database


I have this tables: movie, session (a movie displayed at a datetime) and User.

Users can make reservations for a movie at a concrete session. Drawing it i have it like:

movie **1** ----- **n** sesion
              |
            **n**
             User

I was thinking creating the tables like this:

Movie(id, title, minutes) Sesion(id, idMovie, datetime) User(id, name) Reservation(idSesion, idUser, numTickets)

Would it be ok? or should i include also idMovie at my reservation table?

Thanks.


Solution

  • ...a movie displayed at a datetime... But if you were trying to get a list date time when a movie is in session how could you get to that? I don't think you need movieID in the reserv table but you may want to have a movieID in the session table.

    Then you can get to the movie from knowing the user or find all users attending a movie or session. Adding movie Id in the reservation would be duplicate reference and extra thing to keep synced you don't need because it's treversable by other foreign key relationship.