Name: Sana Salah_ud_din
M.Sc CS (final)
Roll#: 138005
Topic: Keys In Relational
Database
AT A Glance:
Ø
What is :
Ø
A Key ?
Ø
A Super Key ?
Ø
A Candidate Key ?
Ø
A Primary Key ?
Ø
An Alternate Key ?
Ø
A Composite Key?
Ø
A Foreign Key?
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
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
with two attributes i-e branchNo & city.
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
a relation.
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
it uniquely identifies each
tuple in relation Branch.
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
also serve as primary key.
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,
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.