What is the function of the Unique Switch in foreign keys?

Asked

Viewed 40 times

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?

  • 1

    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).

  • 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.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.