Database Concepts CH-7
Database Concepts CH-7
Database Concepts CH-7
com
Downloaded from https:// www.dkgoelsolutions.com
Database Chapter
Concepts 7
om
.c
ns
io
In this chapter
ut » Introduction
ol
ls
» File System
oe
» Keys in a Relational
w
Database
— Nisarga Jain
w
//w
s:
tp
ht
7.1 IntroductIon
After learning about importance of data in the
previous chapter, we need to explore the methods
to store and manage data electronically. Let us
take an example of a school that maintains data
about its students, along with their attendance
record and guardian details.
The class teacher marks daily attendance of the
students in the attendance register. The teacher
records ‘P’ for present or ‘A’ for absent against
each student’s roll number on each working day.
If class strength is 50 and total working days in
2020-21
om
record keeping faced 3) Loss of data in case attendance register is lost or
by them. damaged.
.c
4) Erroneous calculation while consolidating
ns
attendance record manually.
The office staff also manually maintain Student
io
details viz. Roll Number, Name and Date of Birth
ut
with respective guardian details viz. Guardian name,
ol
Contact Number and Address. This is required for
ls
teachers can:
s:
2020-21
om
SName – Name of the student
.c
SDateofBirth – Date of birth of the student
ns
GName – Name of the guardian
io
GPhone – Phone number of the student guardian
GAddress – Address of the guardian of the student ut
ol
Table 7.1 STUDENT file maintained by office staff
ls
Roll SDateof
SName GName GPhone GAddress
oe
Number Birth
5711492685
kg
Daman
2003-07-05 9818184855 26/77, West Patel
tp
2020-21
om
2018-09-02 4 John Dsouza A
2018-09-02 5 Ali Shah P
.c
2018-09-02 6 Manika P. P
ns
7.2.1 Limitations of a File System
io
File system becomes difficult to handle when number of
ut
files increases and volume of data also grows. Following
ol
are some of the limitations of file system:
ls
access data.
tp
2020-21
om
file system. In a more complex system where data files
are generated by different person at different times, files
.c
being created in isolation may be of different formats.
ns
In such case, it is difficult to write new application
programs to retrieve data from different files maintained
io
at multiple places, as one has to understand the
underlying structure of each file as well. ut
ol
(E) Data Dependence
ls
and office staff can only see the student attendance data
but should not be able to modify/delete it. It means
these users should be given limited access (read only)
to the ATTENDANCE file. Only the teacher should be
able to update the attendance data. It is very difficult to
enforce this kind of access control in a file system while
accessing files through application programs.
2020-21
om
users or other programs can access, modify and retrieve
the stored data.
.c
The DBMS serves as an interface between the
ns
database and end users or application programs.
Some database
Retrieving data from a database through special type of
io
management systems
include a graphical commands is called querying the database. In addition,
user interface for users ut
users can modify the structure of the database itself
ol
to create and manage through a DBMS.
Databases are widely used in various fields. Some
ls
databases. Other
database systems use a
applications are given in Table 7.3.
oe
commands to create
and manage databases. Banking customer information, account details, loan details,
w
Crop Loan kisan credit card data, farmer’s personal data, land
//w
2020-21
om
guardian data are maintained only once. hardware and
c) One and more guardians can have the same name. software.
.c
So it will not be possible to identify which guardian • Training users for
is related to which student. In such case, we need
ns
querying.
to create an additional column, say GUID (Guardian • Recurrent cost to
io
ID) that will take unique value for each record in take regular backup
the GUARDIAN file. The column GUID will also be
kept with STUDENT file for relating these two files.
ut and perform recovery
ol
operations.
ls
also. But, phone number can change, and therefore may not
truly distinguish guardian.
kg
GUID GAddress
2020-21
om
466444444666 Sujata P. HNO-13, B- block, Preet Vihar, Madurai
.c
Date RollNumber Status
ns
2018-09-01 1 P
io
2018-09-01 2 P
2018-09-01
ut 3 A
ol
2018-09-01 4 P
ls
2018-09-01 5 A
oe
2018-09-01 6 P
2018-09-02
kg
1 P
2018-09-02 2 P
.d
2018-09-02 3 A
w
2018-09-02 4 A
w
2018-09-02 5 P
//w
2018-09-02 6 P
s:
2020-21
y
Query Result
Qu
er
Query Result
Qu
er
y
om
.c
ns
Student
Database
io
Guardian Catalog
Attendance ut
ol
ls
a database.
w
2020-21
om
To retrieve or manipulate data, the user needs to write
query using a query language called, which is discussed
in chapter 8.
.c
ns
(F) Data Manipulation
Limitations of DBMS Modification of database consists of three operations
io
Increased Complexity: viz. Insertion, Deletion or Update. Suppose Rivaan joins
Use of DBMS increases ut
as a new student in the class then the student details
ol
the complexity need to be added in STUDENT as well as in GUARDIAN
ls
of maintaining
files of the Student Attendance database. This is called
functionalities like
oe
vulnerability:
is called Deletion operation on the database. Suppose
w
centrally, it increases
GPhone should be updated in GUARDIAN file. This is
//w
for all the users. programs used by a DBMS to create database and handle
various queries for data retrieval and manipulation.
2020-21
om
record in relation STUDENT. Similarly, attribute GUID
is placed with STUDENT table for extracting guardian
.c
details of a particular student. If linking attributes are
ns
not there in appropriate relations, it will not be possible
to keep the database in correct state and retrieve valid
io
information from the database.
Figure 7.3 shows the relational database Student ut
ol
Attendance along with the three relations (tables)
ls
Table 7.7 Relation schemas along with its description of Student Attendance
ht
database
Relation Scheme Description of attributes
STUDENT(RollNumber, RollNumber: unique id of the student
SName, SDateofBirth, SName: name of the student
GUID) SDateofBirth: date of birth of the student
GUID: unique id of the guardian of the student
ATTENDANCE AttendanceDate: date on which attendance is taken
(AttendanceDate, RollNumber: roll number of the student
RollNumber, AttendanceStatus: whether present (P) or absent(A)
AttendanceStatus) Note that combination of AttendanceDate and RollNumber will be unique
in each record of the table
GUARDIAN(GUID, GUID: unique id of the guardian
GName, GPhone, GName: name of the guardian
GAddress) GPhone: contact number of the guardian
GAddress: contact address of the guardian
2020-21
om
with 4 attribute/
columns
.c
GUID GName GPhone GAddress
ns
444444444444 Amit Ahuja 5711492685 G-35, Ashok Vihar, Delhi
7110047139
io
111111111111 Baichung Bhutia Flat no. 5, Darjeeling Appt., Shimla
Relation
State
9818184855 26/77, West Patel Nagar, Ahmedabad
101010101010 Himanshu Shah
ut
ol
333333333333 Danny Dsouza S -13, Ashok Village, Daman
7802983674
ls
466444444666 Sujata P. HNO-13, B- block, Preet Vihar, Madurai
oe
2020-21
om
relation different from a data file or a simple table.
Property 1: imposes following rules on an attribute of
.c
the relation.
ns
• Each attribute in a relation has a unique name.
• Sequence of attributes in a relation is immaterial.
io
Property 2: governs following rules on a tuple of a
ut
ol
relation.
• Each tuple in a relation is distinct. For example, data
ls
2020-21
om
A relation can have one or more attributes that takes
distinct values. Any of these attributes can be used to
.c
uniquely identify the tuples in the relation. Such attributes
ns
are called candidate keys as each of them are candidates
io
for the primary key.
ut
As shown in Figure 7.4, the relation GUARDIAN has
ol
four attributes out of which GUID and GPhone always take
ls
unique values. No two guardians will have same phone
number or same GUID. Hence, these two attributes are the
oe
2020-21
om
value if it is not the part of primary key of the foreign table.
The relation in which the referenced primary key is defined
.c
is called primary relation or master relation.
In Figure 7.5, two foreign keys in Student Attendance
ns
database are shown using schema diagram where the foreign
io
key is displayed as a directed arc (arrow) originating from it
ut
and ending at the corresponding attribute of the primary
ol
key of the referenced table. The underlined attributes make
ls
the primary key of that table.
oe
SName SDateofBirth
.d
w
ATTENDANCE
Figure 7.2: StudentAttendance Database with the Primary and Foreign keys
s:
tp
Summary
ht
2020-21
om
Composite Primary Key, Foreign Key.
• Primary key in a relation is used for unique identification
.c
of tuples.
ns
• Foreign key is used to relate two tables or relations.
io
• Each column in a table represents a feature (attribute)
ut
of a record. Table stores the information for an entity
ol
whereas a row represents a record.
•
ls
Each row in a table represents a record. A tuple is
oe
MySQL.
//w
s:
exercISe
tp
ht
2020-21
om
Answer the following:
Table: Sports Preferences
.c
Roll_no Preference
ns
9 Cricket
io
13 Football
17
ut
Badminton
ol
17 Football
ls
21 Hockey
oe
24 NULL
NULL Kabaddi
kg
2020-21
om
students purchase any item from the canteen. The school
wants to create a canteen database to keep track of items
.c
in the canteen and the items purchased by students.
Design a database by answering the following questions:
ns
a) To store each item name along with its price, what
io
relation should be used? Decide appropriate attribute
ut
names along with their data type. Each item and its
price should be stored only once. What restriction
ol
should be used while defining the relation?
ls
the canteen.
tp
2020-21
om
Constraints Primary Key Not Null - 1 XL 620
2 M 810
.c
Table: COST 2 L 890
ns
Attribute UCode Size Price 2 XL 940
io
Constraints Composite Primary Key >0
3 M 770
ut 3 L 830
ol
Table: UNIFORM 3 XL 910
ls
UCode UName UColor 4 S 150
oe
i) 7, Handkerchief, NULL
ht
2020-21
Table: STUDENT
Roll No Name Class Section Registration_ID
11 Mohan XI 1 IP-101-15
om
12 Sohan XI 2 IP-104-15
21 John XII 1 CS-103-14
Table: PROJECT ASSIGNED
.c
22 Meena XII 2 CS-101-14
Registration_ID ProjectNo
ns
23 Juhi XII 2 CS-101-10
IP-101-15 101
io
Table: PROJECT IP-104-15 103
ProjectNo PName SubmissionDate
ut CS-103-14 102
ol
101 Airline Database 12/01/2018 CS-101-14 105
ls
102 Library Database 12/01/2018 CS-101-10 104
oe
2020-21