i have a table with two foreign keys as composite key.
ActivityTbl –
(activityNbr(PK), supervisor(FK), status, type, startDate, endDate, location )
VolunteerTbl –
(volunteerNbr(PK), name, address, contact)
Now I created a table where volunteer’s choices can be stored as per their prefereance rating.
ActivityChoice
(activityNbr(FK), VolunteerNbr(FK), Rating)
So the combination of those 2 FKs make a composite key. I am using sql Server to create a table.
Create ActivityChoiceTbl(
VolunteerNbr int NOT NULL,
ActivityNbr int NOT NULL,
Rank int NOT NULL,
CONSTRAINT PKActivityChoice PRIMARY KEY (VolunteerNbr,ActivityNbr),
CONSTRAINT CKRank CHECK (Rank>0 AND Rank<=9));
So in this case do I need to add another foreign key constrain for both to mention that they are foreign keys?? Am I doing it right?? Thanks
Yes, you need two foreign key constraints. The most direct way in standard SQL is to immediately reference the table.
But adding two more constraint clauses lets you name the constraints, which is a better practice.
If ActivityChoice is a separate table that needs to reference ActivityChoiceTbl, then you also need something along these lines.