Unit No 7
Unit No 7
UNIT#7
DATABASE FUNDAMENTALS
2020
EDITION
2020
EDITION
2020
EDITION
[email protected]
1
COMPUTER SCIENCE NOTES (ICS_PART-I)
What is Data?
Collection of raw facts, figures, numbers or ideas about an object (Person, Place,
and Book etc.) is called Data.
Examples:
✓ NADRA prepared CNIC of Pakistanis by collecting data of people who
belongs to Pakistan.
✓ When a student wants to take admission in a college, he will fill the
admission form to provide all the data about him.
___________________________*****xxxxx*****________________________
What is Information?
Meaningful data is called information.
OR
Examples:
✓ A student’s subject marks are Data while his percentage of marks, grade
and position are Information.
✓ When students fill admission form containing data about them. Then this
data is organized and arranged by eligibility criteria and admission rules, a
merit list will be created. This merit list is in the form of information of
certain students which are eligible for admission.
Name Marks
Merit calculation Name Marks
Aqib 934 If marks >=900
Kaleem 950
candidate is eligible
Qasim 850 Hasnain 935
Aqib 934
Kaleem 950
Merit List
Hasnain 935
2
COMPUTER SCIENCE NOTES (ICS_PART-I)
_________________________*****xxxxx*****__________________________
3
COMPUTER SCIENCE NOTES (ICS_PART-I)
iv. Data Isolation: Data are scattered in various files and the files may be in
different formats. The users have to write new application program to retrieve
data from these files. This is difficult, time-consuming and costly.
v. Limited Data Sharing: Data are scattered in various files and the files may be
in different formats and these files may be stored in different folders may be of
different departments. So due to this data isolation, it is difficult to share data
among different applications.
vi. Integrity Problems: Data integrity means reliability and accuracy of data. For
this purpose, the data stored in database must satisfy various integrity
constraints (rules).
viii. Poor Data Security: Data security means prevention of data access from
unauthorized users. There is very less security in File Processing System as
anyone can easily modify and change the data stored in the files.
___________________________*****xxxxx*****________________________
Advantages of DBMS: The DBMS has the following advantages over the file
management system;
4
COMPUTER SCIENCE NOTES (ICS_PART-I)
___________________________*****xxxxx*****________________________
5
COMPUTER SCIENCE NOTES (ICS_PART-I)
___________________________*****xxxxx*****________________________
Hierarchical Database Model: In this model, data is organized into a tree like
structure. Data is Stored Hierarchically (top down or bottom up) format. Data is
represented using a parent-child relationship.
In Hierarchical DBMS, parent may have many children, but children have only
one parent.
6
COMPUTER SCIENCE NOTES (ICS_PART-I)
Relational Database Model: Relational DBMS is the most widely used DBMS
model because it is one of the easiest. This model is based on normalizing data
in the rows and columns of the tables. Relational model stored in fixed
structures and manipulated using SQL.
7
COMPUTER SCIENCE NOTES (ICS_PART-I)
___________________________*****xxxxx*****________________________
Relation/Table: A table is set of values that are organized using vertical named
column and horizontal rows. A table has a specific number of columns but may
have any number of rows. Each row is called a tuple and each column is called
an attribute or field.
Degree: The total number of attributes in a relation is called degree of the
relation.
8
COMPUTER SCIENCE NOTES (ICS_PART-I)
View
Roll No Name Class
1 Kaleem 1st Year
2 Hasnain 1st Year
___________________________*****xxxxx*****________________________
9
COMPUTER SCIENCE NOTES (ICS_PART-I)
___________________________*****xxxxx*****________________________
Entity: A person, place, object, event or concept about which data is stored in
a database is called an Entity. In ERD, an entity is represented by ‘Rectangle’.
Some examples of entities are as follows;
✓ PERSON: Student, Employee, Patient, Teacher
✓ PLACE: City, State, Country
✓ OBJECT: Machine, Building, Car
✓ EVENT: Sale, Admission, Exam
✓ CONCEPT: Account, Course
10
COMPUTER SCIENCE NOTES (ICS_PART-I)
ROLL NO
___________________________*****xxxxx*****________________________
TEACHER Works
with
MANAGER Manages
EMPLOYEES
In Binary relationship the associations b/w two entities may be described as one-
to-one, one-to-many or many-to-many.
11
COMPUTER SCIENCE NOTES (ICS_PART-I)
PROJECT
___________________________*****xxxxx*****________________________
12
COMPUTER SCIENCE NOTES (ICS_PART-I)
13
COMPUTER SCIENCE NOTES (ICS_PART-I)
Foreign Key
Primary Key
Course ID Course Name
C001 Computer
C002 Physics
C003 Math
___________________________*****xxxxx*****________________________
14
COMPUTER SCIENCE NOTES (ICS_PART-I)
___________________________*****xxxxx*****________________________
Book: The set of all books in the library. Each book has the following attributes;
• Book_ID
• Author
15
COMPUTER SCIENCE NOTES (ICS_PART-I)
• Title
• Price
• Available
Member: The set of all the library members. A member has the following
attributes;
• Member_ID
• Name
• Address
• Phone
Publisher: The set of all the publishers of the books. A publisher has the
following attributes;
• Pub_ID
• Name
• Address
N 1
Author BOOK Publish PUBLISHER
Book_ID N Pub_ID
Phone
Issue_Date Borrow
1 MEMBER Name
Due_Date Address
Return_Date
Member_ID
16
COMPUTER SCIENCE NOTES (ICS_PART-I)
Teacher: The set of all teachers in a department. A Teacher has the following
attributes.
• Teacher_ID
• Name
• Phone
Course: The set of all the courses offered by a department. A Course has the
following attributes;
• Course_ID
• Course Name
• Duration
Student: The set of all students of the institution. A Student has the following
attributes;
• Student_ID
• Name
• Class
• Address
17
COMPUTER SCIENCE NOTES (ICS_PART-I)
Address
Dept_ID
Class
Has
N N
Teacher_ID
Course_ID
COURSE
N
Name
Course Name
N N
Phone
Duration 1 TEACHER
Ticket Booking System: In the Ticket Booking System the following entities
and attributes can be identified.
Passenger: It is a set of all the passengers who want to travel. Each Passenger
has the following attributes;
• Ticket_No
• Name
• Address
• Phone
Seat: It is a set of all seats available for the passengers. Each Seat has the
following attributes;
• Seat_No
• Name
• Class
Flight: It is a set of all the flights offered by an airline. A flight has the
following attributes;
18
COMPUTER SCIENCE NOTES (ICS_PART-I)
• Flight_No
• Departure Date
• Departure Time
• Arrival Date
• Arrival Time
Airline_Code Ticket No
AIRLINE PASSENGER
Name
1 N R1
Name
Addres
s
Flies Phone
Flight_No
Books
Arrival Date N 1
19
COMPUTER SCIENCE NOTES (ICS_PART-I)
Doctor: It is a set of all doctors in a hospital. Each doctor has the following
attributes;
• Doctor_ID
• Name
• Specialization
• Qualification
Patient: It is a set of all patients in a hospital. Each patient has the following
attributes;
• Patient_ID
• Age
• Address
Medicine: It is a set of all the medicines given to a patient. A medicine has the
following attributes;
• Medicine_Code
• Price
• Quantity
20
COMPUTER SCIENCE NOTES (ICS_PART-I)
Specialization
Qualification
Name DOCTOR
1
Doctor_ID
Treats
N
Patient_ID
PATIENTM
Medicine_Code
N
Address
Quantity
Age N
Price
MEDICINE
___________________________*****xxxxx*****________________________
STUDENT
Class Address
___________________________*****xxxxx*****________________________
1 10 1 70 Math Teacher
2 10 2 75 Physics Teacher
3 11 1 80 Computer Teacher
Together, Student_ID + Subject_ID forms a Composite Primary Key for this table,
which can be the Primary key.
22
COMPUTER SCIENCE NOTES (ICS_PART-I)
If X → Y → Z Then X → Z
___________________________*****xxxxx*****________________________
23
COMPUTER SCIENCE NOTES (ICS_PART-I)
Repeating Groups: When there exists more than one values of a non-key
attribute against a single primary key attribute, then it is known as repeating
groups.
Example: ‘Employee Table’
Proj_No Proj_Name Emp_No Emp_Name Job_Class Charge_Per_Hour Hours
1 Evergreen 101 Hasnain HW Eng 1000 10
102 Kaleem SW Eng 2000 15
103 Qasim SW Eng 2000 20
2 IT_Zone 104 Afran Programmer 900 09
105 Aqib DBA 1500 15
106 Sabir WebDesigner 800 08
First Normal Form (1NF): A Relation is said to in 1NF if it follows the following
rules:
1. A Column should contain values that are of the same type.
2. Each Column should contain a single value.
3. Each Column should have a unique name.
The ‘Employee’ table contains repeating groups. To normalize the above table,
all repeating groups must be eliminated.
‘Employee Table’
Proj_No Proj_Name Emp_No Emp_Name Job_Class Charge_Per_Hour Hours
1 Evergreen 101 Hasnain HW Eng 1000 10
1 Evergreen 102 Kaleem SW Eng 2000 15
1 Evergreen 103 Qasim SW Eng 2000 20
2 IT_Zone 104 Afran Programmer 900 09
2 IT_Zone 105 Aqib DBA 1500 15
2 IT_Zone 106 Sabir WebDesigner 800 08
24
COMPUTER SCIENCE NOTES (ICS_PART-I)
In the above table, the attribute Proj_No does not identify each record uniquely
so the attributes Proj_No and Emp_No together makes a composite primary key
that will uniquely identify each record.
‘Employee Table’
25
COMPUTER SCIENCE NOTES (ICS_PART-I)
‘Employee Table’
Transitive Dependency
X
AJAB NOOR
Lecturer in Computer Science, GPGC Bannu
26