locked
Many to Many to Many Relationships RRS feed

  • Question

  • New to SQL Database design, however i have a quick question that was already discussed in another forum post however I would like to take it one step further. The original post was as follows:

    "I just followed a tutorial which gives the example of a many-to-many relationship. In this case, how to allow movies to have multiple Genres.

    However, I would like to expand on this example, and try something slightly more complicated. Basically I am looking to something like MANY-to-MANY-to-MANY or MANY-to-MANY-to-ONE.

    Suppose I want to create a table called SCENE. SCENE can have more than one ACTOR, and each ACTOR can have more than one ACTION. I wonder how would I do something like this?

    At first I tried doing a separate many-to-many relationship table for ACTOR, and another for ACTION. So I created two joining tables (SceneToActor and SceneToAction). This way I can add multiple actors and actions to a scene. However, I can't tell which actor is doing what action in the scene.

    I wonder if the answer would be to create a many-to-many relationship between the SceneToActor table and the Action Table, so I would have something like SceneToActorToAction as the joining table."

    The answer to this question was given as:


    where you have an intermediate ScenesActors table that just lists the SceneID and ActorID (alongwith its own ID field [SceneActorID] as primary key).

    You then have the ScenesActorsActions table which has the SceneActorID and ActionID (along with its own ID field [SceneActorActionID] as PK).

    The ScenesActors table lists each actors are in which scenes.

    The ScenesActorsActions table lists what they do.

     

    Scenes --< ScenesActors >-- Actors
                           |
                           |
                          ^
    Actions --< ScenesActorsActions

    However, in the design of my database, say Actions already had a one-to-many relationship with another table titled ActionPossibilities in which every row was a possible action that could take place (essentially making the possible actions that could occur dynamic). How then would you effectively create the relationship described above? The problem i am running into is that the primary key for the Actions table is used as a foreign key in the ActionPossibilities table. Is something like this possible under the current design?

    Thanks for the help!

    Thursday, April 3, 2014 3:14 AM

Answers

  • However, in the design of my database, say Actions already had a one-to-many relationship with another table titled ActionPossibilities in which every row was a possible action that could take place (essentially making the possible actions that could occur dynamic). How then would you effectively create the relationship described above? The problem i am running into is that the primary key for the Actions table is used as a foreign key in the ActionPossibilities table. Is something like this possible under the current design?

    If ActionPossibilities is a predefine thing for a specific Action then I think 1:N is ok. What if an Action does not have any ActionPossibilities ? I think it is important to know the significance and business need of "Action Possiblilities" wrt an Action. I assume that the intention is to pick the right action for a scene. Or is it right action for an actor?  

    Here I have a quick logical design, refer below. I have not added ActionPossiblities yet. Just need to clear first.

    -----------------
    MOVIE
    MovieID int (PK)
    MovieName
    Description
    Genres varchar  (FK)   (Art/Entertainment/Spoken/AudioVisual : Further normalize it)
    DirectorID int (FK reference CASTCREW.CastCrewID)
    -----------------
    CASTCREW
    CastCrewID  int (PK)
    CastCrewName
    Designation
    Sex
    -------------------
    SCENE
    SceneID int (PK)
    SceneDescription
    SceneType (fight/angry/romance etc)
    MovieID     (FK reference MOVIE.MovieID)
    SceneCastCrewID  (FK reference SCENECREWROLE.SceneCastCrewID)

    -------------------
    ACTION
    ActionID int (PK)
    SceneID int (FK reference SCENE.SceneID)
    CutStatus varchar  (accept/decline)
    Ranking  int    (best shot prioritization)

    ------------------------

    SCENECREWROLE
    SceneCastCrewID  int (PK)
    CastCrewID  (FK reference CASTCREW.CastCrewID)
    PrimaryRole (actor/actress/....)
    SceneDescription
    --------------------

    The relation between SCENE and ACTION is 1:N. Out of N Action 1 shot will be the final and that is identified by CutStatus.


    Regards, RSingh

    • Proposed as answer by Sofiya Li Tuesday, April 8, 2014 2:45 AM
    • Marked as answer by Sofiya Li Monday, April 14, 2014 1:29 AM
    Sunday, April 6, 2014 2:44 AM
    Answerer