2. AT A Glance:
Ø
What is :
Ø
A Key ?
Ø
A Super Key ?
Ø
A Candidate Key ?
Ø
A Primary Key ?
Ø
An Alternate Key ?
Ø
3. relational Key:
A KEY is an attribute or set
of attributes that uniquely
identifies a TUPLE in a relation.
There are two main types of key:
A Super Key
and a Foreign key
Relational
Keys
Super
Key
Foreign
Key
Candidate
Key
Primary
Key
Alternate
key
Candidate
Key
4. Super Key:
An attribute, or set of attributes, that uniquely
identifies a tuple within a relation.
A Super key may contain additional attributes that are
not necessary for unique identification.
A super key is the most
general type of key.
EXAMPLE:
As shown in the figure the relat-
ion Branch has a super key
5. Candidate key:
A key which is the candidate for being selected as a
primary key.
A candidate key contains only the attributes which can
uniquely identify a tuple in a relation.
As shown in the figure --- in the
relation Branch the attributes
branchNo & postcode can serve
as candidate keys because both
can uniquely identify a tuple in
6. Primary key:
The candidate key that is selected to identify tuples
uniquely within the relation.
Some most important points about primary key are:
A relation can have only one primary key.
Each value in primary key attribute must be unique.
Primary key cannot contain null values.
As shown in the figure----
the attribute branchNo can
serve as primary key because
7. Alternate key:
The candidate keys that are not selected as primary
key are known as alternate keys.
As shown in the figure
the relation Branch has
branchNo serving as pri-
mary key and postcode
serving as alternate key
because postcode can
8. Composite Key:
A primary key that consists of two or more attributes is
known as COMPOSITE KEY.
As shown in the figu-
re– the relation Branch
has two attributes
serving as primary key
so this is a composite
key,
9. Foreign key:
An attribute, or set of attributes, within one relation
that matches the candidate key of some relation..
As shown in the figur-
e in the relation Staff
The attribute branchNo
is the foreign key
because it is the prim-
ary key in the relation
Branch.