We must have a way to specify how tuples within a given relation are distinguished; no two tuples in a relation are allowed to have exactly the same value for all attributes.
Let , where is a relational schema for the relation .
-
Superkey
is a superkey of if value for are sufficient to identify a unique tuple of each possible relation instance .
- i.e.,
-
Candidate key
A superkey is a candidate key if is at its minimum value.
-
Primary key
One of the candidate keys is selected to be the primary key.
- Usually the most efficient one in terms of computation cost is chosen.
- Primary key is chosen by the database designer as the principal means of identifying tuples within a relation.
- Also referred to as the primary key constraint.
Let be an attribute of relations .
-
A foreign-key constraint from attribute(s) of relation to the primary-key of relation states that on any database instance, the value of for each tuple in must also be the value of for some tuple in .
- i.e., such that
-
Attribute set is called a foreign key from , referencing .
- The relation is also called the referencing relation; is also called the referenced relation.