Skip to content
Advertisement

there is no unique constraint matching given keys for referenced table in SQL

I have three tables:

  1. Test
  2. Student
  3. Student registration, it’s purpose is to a student to a course.

I get this error when I compile the third table:

I have no idea why, any help will be highly appreciated.

Advertisement

Answer

You want a compound foreign key rather than two distinct keys:

Why you need that is because table TEST as has compound unique key on these two columns:

So for table STUDENT_REG to unambigously refer to a row in TEST, you need the combination of both columns, which means a 2-columns foreign key rather than two distinct foreign keys.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement