Reputation: 35
I need your suggestion on how to implement SQL Server table relationships.
I have many customers, each holds a unique id (customerID
)
each customer can have many categories associated (categoryID
)
each customer can have many sub categories (subCategoryID
) for
when a customer logs in I know its CustomerID
, CategoryID
and SubCategoryID
.
customer plans in advance how many hours will work every week for the year to come (on december 2014 plans 52 weeks of 2015)
every day a customer reports if they worked or took a day off.
I thought of having a table called WeeklyPlanning
with columns:
CustomerID, CategoryID, SubCategoryID, Year, WeekNumber, WorkingHoursPlan
and another table called DailyWorkingHours
with columns:
Dates, WorkingHours
My questions:
I don't know how to combine these two tables together, use a compound key? (CustomerID, CategoryID, SubCategoryID, Year, WeekNumber
) or maybe generate a unique PK in WeeklyPlanning
that will be used as a FK in DailyWorkingHours
?
I'm looking for the best way to implement this.
thanks
Upvotes: 1
Views: 120
Reputation: 754388
Do you really want to specify FIVE column's values for each JOIN
between those two tables? That's what you'll have to do if you have a compound primary key made up from five columns - you need all those columns in your child table as well, and you need to always specify all five columns when doing a JOIN ..... ouch ......
If not - use a surrogate column in WeeklyPlanning
(a WeeklyPlanningID INT IDENTITY(1,1)
) to simplify your life significantly!
Upvotes: 2