Adam
Adam

Reputation: 10016

Problems declaring foreign keys, SQL Server

I'm trying to create a table called Enrollments with two attributes that reference the foreign keys of another table. The schema for Enrollments is:

enter image description here

I'm trying to make SectionNo and Year of Enrollments reference SectionNo and Year of the CourseSections table (already created). Here is the schema for that relation:

enter image description here

Here is how I'm trying to add the foreign key constraints when I create the enrollments table:

enter image description here

I'm getting the error:

SQL71516 :: The referenced table '[dbo].[CourseSections]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column is a computed column, it should be persisted.

Upvotes: 0

Views: 1126

Answers (1)

Anoop LL
Anoop LL

Reputation: 1575

Make SectionNo and Year as candidate keys.

Upvotes: 0

Related Questions