Reputation: 101
I am developing a management system for a fitness gym. I couldn't get to identify how to visualize my workout plans in a DB. I have this idea (see image below) where I have a plan table and an exercise table.
The idea here is that in every plan, there are 21 exercises (9 for upper, 9 for lower, and 3 for abdominals). This is because a plan has 3 days, and for each day is a different 3-exercise plan for the upper and lower body and a different abdominal exercise each day. Am I doing this right by putting 21 foreign keys of the same exercise ID into the plan table? And if I am doing this right, how do I connect this in an ER diagram? Do I have to connect each foreign key or do I just have to put one cardinality between the two tables?
Upvotes: 0
Views: 95
Reputation: 19232
No you are not doing it right, you are missing a table from your database model.
Do this:
Plan -> Plan_Exercises -> Exercises
Plan_Exercises
table has a Plan_Id
column with a Foreign Key constraint to the Primary Key Id column on Plan
tablePlan_Exercises
table has a Exercise_Id
column with a Foreign Key constraint to the Primary Key Id column on Exercise
tablePlan needs a one to many relationship to exercises, adding the "middleman" PLan_Exercises
table provides this relationship.
Upvotes: 1