I have three tables a DaysOfWeek, an OpeningHours and a Shops:
DaysOfWeek
Id tinyint PK
Day nvarchar(10)
OpeningHours
Id int PK
DaysOfWeekId tinyint PK
OpeningHour varchar(16)
Shops
Id int
...
OpeningHoursId int PK
...
ALTER TABLE Shops
ADD CONSTRAINT FK_Shops_OpeningHours
FOREIGN KEY (OpeningHoursId) REFERENCES OpeningHours(Id);
I cannot link the Shops and the OpeningHours tables due to this error:
There are no primary or candidate keys in the referenced table 'OpeningHours' that match the referencing column list in the foreign key 'FK_Shops_OpeningHours'.
Maybe it is not possible because of the OpeningHours' composite key?