Page 240 - PYTHON-12
P. 240
Therefore, in reference to Fig. 12.11, in the above Student relation:
• There are 10 tuples (i.e., cardinality=10) and 4 attributes (i.e., degree=4).
• Roll number, Name, Address and Gender are the attribute names.
• The first tuple contains the values (1, “Rinku Sharma”,”Tilak Nagar”,’F’).
• The domain of the attribute Gender is (M,F).
12.5 DATABASE KEYS
Keys are a very important part of relational database. They allow us to identify an attribute or a
set of attributes on the basis of which a table is identified. They are used to establish and identify
relation among two or more tables. They also ensure that each record within a table can be uniquely
identified by a combination of one or more fields within a table.
The different types of keys in a RDBMS are as follows:
KEY DESCRIPTION
Primary Key A primary key is an attribute or a group of attributes that can uniquely identify tuples within the relation.
Candidate Key A candidate key is one that is capable of becoming the primary key. (i.e., candiate for primary key
position).
Alternate Key A candidate key that is not the primary key is called an alternate key.
Foreign Key A non-key attribute, whose value(s) are derived from the primary key of some other table, is known
as foreign key in its current table.
Let us discuss these keys in detail.
1. Primary Key: A primary key is a set of one or more attributes/fields which uniquely identifies
a tuple/row in a table. The salient features of a primary key are as follows:
(a) It is always unique in nature, i.e., non-redundant. It does not have duplicate values in a
relation.
(b) It arranges the table in its own order.
(c) It cannot be re-declared or left null.
(d) One table can have only one primary key; however, primary key can be a combination of
more than one field. For example, roll number along with admission_no can be combined
together and can be declared as a primary key in the relation Student. In the table Item
given below, Item_id is the primary key while Supp_id (supplier id) is the primary key in
the table Supplier.
Table: Item Item_name Qty Table: Supplier
Area
Supp_id
Item_id
Computer Science with Python–XII 12.10 Primary Key DVD Alternate Key S04 Candidate Keys Alternate Key
I101
400
Printer
Ashok-Vihar
S01
Noida
200
S02
I102
CD
150
CP
I104
I105
S05
Mouse
Punjabi Bagh
300
Keyboard
I103
180
500
Cable
I109
Primary Key
Candidate Keys
Fig. 12.12: Keys in a Database (Tables)