Question

I'm conceptualizing a database. I want a table with 3 columns (1 is the PK, the other 2 are FK) and I want to make so that there can only be one element with each combination of columns. Is the fact that both are foreign keys enough to guarantee uniqueness for the combination of both? (There can only be one row with same combination of values for both those columns). Should I also make them a composite unique key?

Was it helpful?

Solution

Is the fact that both are foreign keys enough to guarantee uniqueness for the combination of both?

Nope.

it should I also make them a composite unique key?

Correct. If you create a composite unique key that includes them - you guarantee the pairs to be unique (unless they accept NULL values)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top