Can someone help me understand this as I’m not sure if I should include a primary key in this one, because it doesn’t look like I need it.
I have two table structures as follow:
Table 1: programs
program_id
cycle_unitTable 2: program_has_days
day
week
program_id
A program can take many days to complete, so the program has a schedule which is in table 2. The schedule list the day in the week (example day 1 of week 1, then day 3 of week 2) that the program can be completed. So here, it has a one to many relationship. I’m wondering should I put an primary key (id) to table number 2?
I don’t think I’ll need the primary key, as I won’t be referring to the schedule directly. I always refer to the program_id to get the schedule. In this case, program_id can’t be the primary key because it is not unique.
Yes, good practice; No, not required. It’s good practice for every table to have a primary key. This will help you later if you decide you do actually need to reference the table’s data – even if it’s just to delete a few rows without having to specify some other unique set of its fields.