Search code examples
databaseinheritanceentity-relationship

Should inheritance be used when sub-entities have the same attributes (ER-diagrams)?


I was wondering, when modeling a database, should inheritance be used if the sub-entities have the exact same attributes?

Let me explain with an example. In competitions for weightlifting, weightlifters do two different moves: "Snatch", and "Clean and jerk". They have three tries for each move. I modeled this in the following way:

enter image description here

At first, it made sense to me, because the two moves have a lot of attributes in common, which are in the parent-entity called Result. However, "Snatch" and "CleanAndJerk" also have completely equal attributes. This seems redundant. Though, it does not seem much better to place everything in the "Result"-entity either.

Is this a good choice when designing a database?


Solution

  • In this situations what you really need is a polymorphic table.
    I think it's better if you do it this way:

    1. Move table. columns: FirstTry,SecondTry,ThirdTry,BestTry,MoveTypeId.
    2. MoveType table. columns: MoveTypeId,MoveTypeName,MoveTypeDescription.

    then simple the Move has a Foreign Key to MoveType table.