Page 241 - PYTHON-12
P. 241
2. Candidate Key: A candidate key refers to all the attributes in a relation that are candidates or
are capable of becoming a primary key. We mark it virtually.
In the above Item table, Item_id and Item_name are the candidate keys. Out of these keys,
Item_id is the primary key and Item_name becomes the alternate key. Similarly, in the case of
Supplier relation, Supp_id and Area are the candidate keys, Supp_id is the primary key and Area
becomes the alternate key. Thus, the equation becomes:
Candidate Keys – Primary Key = Alternate Key
3. Alternate Key: A candidate key that is not the primary key is called an alternate key. In other
words, any attribute that is a candidate for the primary key, i.e., which is capable of becoming a
primary key but is not a primary key, is an alternate key. For example, in a Customer table, cust_
name is the alternate key. Similarly, in the above table Item, Item_name becomes the alternate
key.
4. Foreign Key: A foreign key is a non-key attribute whose value is derived from the primary key
of another table; in other words, a primary key in some other table having relationship with the
current or original table.
Foreign Key
Table: Employee Table: Department
Item_id Emp_name Desig_code Desig_code Designation
E01 Ankur Mehta Mgr Mgr Manager
E02 Deepika Gupta Dir Dir Director
E04 Arnav Bansal Asst_mgr Acc Accountant
E03 Harshit Singh Acc Asst_mgr Assistant Manager
E05 Kirti Dubey Mgr
In the above table, Desig_code is the primary key in the table Department which, when related
with the table Employee, becomes a foreign key to it.
This was all about the database concepts. Now, we will be moving on to their implementation
using SQL.
12.6 INTRODUCTION TO SQL
Database Management Systems (DBMS) are not a
new concept and had been first implemented in the
1960’s. With time, database technologies evolved
a lot while usage and expected functionalities of
databases increased immensely. These days, there is
Online Electricity
no organization which does not manage its data and
Telephone Directory Billing System
records using some type of DBMS. An online telephone
directory uses DBMS to store data pertaining to people, phone numbers and other contact details.
Apart from this, your electricity service provider uses a DBMS to manage billing, client-related
issues, to handle fault data, etc. Not to forget, Facebook—it needs to store, manipulate and present Relational Database and SQL
data related to its members, their friends, member activities, messages, advertisements and a lot
more.
12.11