- You already know what "key" attributes are from the ER-model:
click here
The key concept in the relational model is defined in an "unusually"
difficult manner (well, in a Mathematical manner)...
- Super key:
- Superkey =
a set of attributes
in a relation R
such that
no 2 different tuples
will have the same values
for that set of attributes
|
Mathematically speaking:
A set of attribute SK is a
superkey
if and only if:
∀ t1, t2 in R:
t1[SK] ≠ t2[SK]
|
- Key:
- Key:
is a minimal
set of attributes in a relation R
such that no 2 tuples will have the same values (for that
set of attributes)
|
I.e., a
key is a
minimal superkey.
- Candidate key:
- Primary key:
- Primary key =
the
key
that is chosen to be used to
identify tuples
in a relation.
|
Once you have chosen
the primary key for some
relation,
you must
use that
primary key
throughout the database
(or else, you database career life will be
very miserable)
- Foreign key:
- Foreign key =
a set of attributes inside some
relation R1
that is
the
primary key of
another relation R2
|
Example:
ID in
GradeReport is
a foreign key:
- The attribute
ID in
the relation
GradeReport (= R1)
is the
primary key in
relation Student (R2)
|
CID in
GradeReport is also
a foreign key:
- The attribute
CID in
the relation
GradeReport (= R1)
is the
primary key in
relation Course (R2)
|