0
If the foreign key will always reference a primary key, which by definition is unique, then what is the need to define the Unique Constraint in foreign keys?
0
If the foreign key will always reference a primary key, which by definition is unique, then what is the need to define the Unique Constraint in foreign keys?
Browser other questions tagged mysql sql database
You are not signed in. Login or sign up in order to post.
If the foreign key is unique, it means that each record of the other table can only be referenced once. This may or may not be desirable, depending on your data model. For example, if an address table has a unique foreign key for a city table, there can only be one address in each city (i.e., in this example clearly the foreign key should not be unique).
– bfavaretto
For some reason the model if there is only one reference in the referenced table, for example table "clients", "current account" and "charge" for a debit account the table "charge" has as fk "clients" and "current account" but only one account is allowed in the charge , would be the Unique in "charging" bad example maybe but did not occur to me another.
– Motta
-> Foreign key with UNIQUE
– Bacco