0% found this document useful (0 votes)
7 views26 pages

Unit No 7

The document provides comprehensive notes on database fundamentals, including definitions of data and information, file management systems, and database management systems (DBMS). It discusses various database models, SQL types, and essential database terminologies, as well as the role of a database administrator. Additionally, it outlines steps for planning a database and introduces the concept of data modeling and entity-relationship diagrams.

Uploaded by

fawazkhan2324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views26 pages

Unit No 7

The document provides comprehensive notes on database fundamentals, including definitions of data and information, file management systems, and database management systems (DBMS). It discusses various database models, SQL types, and essential database terminologies, as well as the role of a database administrator. Additionally, it outlines steps for planning a database and introduces the concept of data modeling and entity-relationship diagrams.

Uploaded by

fawazkhan2324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

COMPUTER SCIENCE NOTES (ICS_PART-I)

Written By: Ajab Noor


Lecturer in Computer Science GPGC Bannu

COMPUTER SCIENCE NOTES (ICS_PART_I)

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.

Name F/Name D.O.B Domicile Address

Kaleem Mir Daraz 1-4-2004 Bannu Mamash Khel

Hasnain Abid ur Rehman 5-3-2004 Bannu Mamash Khel

___________________________*****xxxxx*****________________________

What is Information?
Meaningful data is called information.

OR

The Processed data is called information.

DATA PROCESS INFORMATION

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.

Data Process Information

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)

Differentiate b/w Data and Information?


Data vs Information
Basis for Comparison Data Information

Definition Collection of raw facts, figures, The Processed data is


numbers or ideas about an called information.
object is called Data.

Input/output Data is used as input in the Information is the output


computer. of computer.

Value/useful Data alone is meaningless and Information is useful,


valueless. meaningful and valuable.

Dependency Data is an independent entity. Information depends on


data.

Lost Data is difficult to reproduce if Information is easier to


lost. reproduce if lost.

Form Unorganized Organized

_________________________*****xxxxx*****__________________________

What is File Management System? Discuss limitations of File


Management System?
File Management System: It is also known as Conventional File System or
simply file system. It is a method of storing, organizing and collection of data in
the form of files on the secondary storage devices. These files are accessed with
the help of certain file handling program developed in programming language
like C/C++, VB etc. Conventional file system is no longer used due to its demerits
and limitations.

Limitations of File Management System: It has the following limitations;


i. Data Redundancy: It is possible that the same information may be duplicated
in different files. This leads to data redundancy that results in memory wastage.
ii. Inconsistency: Because of data redundancy, it is possible that data may not be
in consistent state. It means if a data item needs to be changed then all the files
containing that data item need to be changed, otherwise the data will remain
inconsistent.
iii. Difficulty in Accessing Data: Accessing data is not convenient and efficient in
file management system. It requires extensive programming to retrieve data
from file management system.

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).

vii. Atomicity Problems: Any operation on database must be atomic. It means


the operation must happen entirely or not at all.

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.

ix. Intensive Coding: In file management system, it is difficult to write a separate


program for searching, editing, deletion and updating.

x. Data Program Dependence: In file management system, changes in the


format and structure of data and records in a file require that changes be made
to all the programs that use that file.

___________________________*****xxxxx*****________________________

Define Database and Database Management System? Also discuss the


advantages of DBMS over the File Management System?

Database: A shared collection of logically related data, designed to meet the


information needs of an organization is called Database.

Examples: Following are some examples of database system;

• Customer Information System


• Library Management System
• Student Management System
• Banking System

Database Management System: Database Management System (DBMS) is


a collection of programs that allow the users to create, maintain and manipulate
databases. It also helps to control access to the database.

Examples: Microsoft Access, Microsoft SQL Server, Oracle, Sybase, MySQL,


Ingres etc.

Advantages of DBMS: The DBMS has the following advantages over the file
management system;

4
COMPUTER SCIENCE NOTES (ICS_PART-I)

Controlled Data Redundancy: The file management system contained multiple


copies of the same data that leads to data redundancy. This is prevented in a
database as there is a single database and any change in it is reflected
immediately. Because of this, there is no chance of encountering duplicate data.
Data Consistency: Minimizing data redundancy leads to consistent data. By
controlling data redundancy, data inconsistency is greatly reduced. Any change
will automatically take effect at all places in a database.
Data Sharing: As a database is a shared collection of logically related data, so the
authorized users are allowed to use the shared database according to their
needs and rights.
Enforcing of Standards: Since all access to database must be through DBMS so
standards are easier to enforce. Standards may relate to the naming of data,
format of data and structure of data.
Security: In a database management system, only authorized users should be
allowed to access the database and their identity should be authenticated using
a username and password.
Privacy: The privacy rule in a database means only the authorized users can
access a database according to its privacy constraints. There are levels of
database access and a user can only view the data he is allowed to.
Data Integrity: Data integrity means that the data is accurate and consistent in
the database. Data Integrity is very important as there are multiple databases in
a DBMS. All of these databases contain data that is visible to multiple users. So,
it is necessary to ensure that the data is correct and consistent in all the
databases and for all the users.
Backup and Recovery: Database Management System automatically takes care
of backup and recovery. The users don't need to backup data periodically
because this is taken care of by the DBMS. Moreover, it also restores the
database after a crash or system failure to its previous condition.
Program Data Independence: The separation of data from the application
program that use the data is called data independence. In database, the data can
be change without changing the application program that process the data.
Support for multiple views: DBMS may allow different users to see different
views of the database according to their needs. For example, one person may
want to view the admission detail of a student while another person may be
interested to view the hostel detail of a student.
User Friendliness: Using DBMS user can easily access and manipulate data in a
database. DBMS provides a user-friendly interface for interaction with database.

___________________________*****xxxxx*****________________________

5
COMPUTER SCIENCE NOTES (ICS_PART-I)

What is a Database Administrator? Briefly explain the role of the


Database Administrator (DBA) in a Database?
Database Administrator is the person who uses software to store and organize
data in a database. They make sure that data is available to users and secure
from unauthorized access. OR A Database Administrator (DBA) is individual or
person responsible for controlling, maintenance, coordinating and operation of
database management system.

Role of DBA: Some responsibilities of a DBA include:


• Implementation of Data Models
• Installation and upgradation of database server
• Schema definition
• Data integrity
• Database design
• Performance issues
• Security
• Granting of authorization for data access
• Backup and recovery
• Routine maintenance

___________________________*****xxxxx*****________________________

What is a Database Model? Explain various types of Database Models?


Database Model: A database model is a set of rules which state that how data
can be stored, organized and manipulated in a database system. Few common
database models include:
a. Hierarchical Database Model
b. Network Database Model
c. Relational Database Model
d. Object Oriented Database Model
e. Object Relational Database Model

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)

Network Database Model: It is similar to a hierarchical database model


except that each child can have more than one parent record. A child record is
called ‘member’ and a parent record is called ‘owner’. The advantage of this
model is to establish relationship b/w different branches of data records.

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.

Object-Oriented Model: In Object-oriented Model data stored in the form of


objects. The structure which is called classes which display data within it. It
defines a database as a collection of objects which stores both data member’s
values and operations.

Object Relational Database Model: An Object relational model is a


combination of Object-oriented database model and Relational database model.
So, it supports objects, classes, inheritance etc. just like Object Oriented models
and has support for data types, tabular structures etc. like Relational data model.
One of the major goals of Object relational data model is to close the gap
between relational databases and the object-oriented practices frequently used
in many programming languages such as C++, C#, Java etc.
___________________________*****xxxxx*****________________________

7
COMPUTER SCIENCE NOTES (ICS_PART-I)

What is Structured Query Language (SQL)? Explain its types?


Structured Query Language: SQL is a standard language for accessing and
manipulating databases. It is used to communicate with a database. SQL
statements are used to perform tasks such as update data in a database, or
retrieve data from a database.

Types of SQL: SQL is divided into the following languages:


• Data Definition Language (DDL)
• Data Manipulation Language (DML)
• Data Control Language (DCL)

Data Definition Language: It is a database language that defines the


structure in which data are stored. These structures are schemas, tables, views,
records etc.

Data Manipulation Language: It is a database language that’s used to


retrieve and manipulate data in a relational database. It is used for selecting,
inserting, deleting and updating data in a database.

Data Control Language: It is a database language used to control access to


the data in a database. For example, giving rights to the users and revoking
(withdraw) of the already given rights.

___________________________*****xxxxx*****________________________

Discuss all basic terminologies used in a database?


The following are some basic database terminologies.
Field/Attribute/Column: The property or characteristics of an entity is called
Attribute. For example, Roll No, Name, Age, Class, Address of a student are his
attributes.
Attribute Domain: A set of all possible values for an attribute is called Attribute
Domain. For example, the value in the field “Class” can be the name of any
taught classes.
Record/Tuple/Row: A collection of related fields treated as a single unit is called
a Record or Tuple. In relational databases, a Row or Record or Tuple represents
a single occurrence of an entity. For example;
Roll No Name Class Age Address
1 Kaleem 1st Year 16 Bannu

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)

Cardinality: The total number of record or tuples in a relation is called Cardinality


of the relation.
View: A view is a dynamic and virtual table that may not exist in the database but
is derived from one or more base tables. For example, a user wants to view few
columns of a base table instead of all columns. A view is created to fulfill his
request.
Base Table
Roll No Name Class Age Address
1 Kaleem 1st Year 16 Bannu
2 Hasnain 1st Year 17 Bannu

View
Roll No Name Class
1 Kaleem 1st Year
2 Hasnain 1st Year

Data Type: It is the classification of a particular type of information. Data type


describes that which type of data will be stored in a particular field of a relation.
Integer, floating-point and character (text) are the common data types.
Key: An attribute or set of attributes that uniquely identifies each record in a
table is called a Key. It’s also called an Identifier. For example, Student’s Roll No,
Employee Id, Customer No etc are key fields.

___________________________*****xxxxx*****________________________

Explain various steps of planning a database?


The process of database design is divided into different steps. These are:
 Problem Identification/definition
 Feasibility Study
 Requirement Analysis
 Identifying Entities and Attributes
 Assigning Names to Tables and Columns
Problem Identification/definition: In this step, the problem arises in the current
system is identified. For example, the admission section head has getting
complaints of bad services about admission system from students. This may lead
to an initial investigation to find whether a new system can solve the problem or
not.
Feasibility Study: It is also known as pilot study, is conducted to determine
whether new database system should be developed or not. Feasibility study
depends on various factors which are; development time, development cost,
resources needed, training of personals and maintenance of the new system.

9
COMPUTER SCIENCE NOTES (ICS_PART-I)

Requirement Analysis: It is the process of understanding the customer needs


and expectations from the new system. It describes that how a new system will
work. For this purpose, the database analyst will spend a lot of time with the end
users within the organization to observe the current system.
Identifying Entities and Attributes: In this step, all the entities and attributes are
identified. Entities are converted into tables and attributes to columns of the
tables.
Assigning Names to Tables and Columns: There are no standard rules for naming
tables and columns but all names should be meaningful and unique throughout
the database. For example, “Customer” for customers table.

___________________________*****xxxxx*****________________________

What is Data Model? Explain Entity Relationship Diagram?


Data Model: A data model is a logical representation of data in an organization.
It is used to describe the elements of a database system and their relationships.
Data modelers often use multiple models to view the same data and ensure that
all processes, entities, relationships and data flows have been identified.

Entity Relationship Model: Entity Relationship model is expressed in terms


of entities, the relationships among those entities and the attributes of both
entities and their relationship. Diagrams created by this process are called Entity
Relationship Diagram.

Entity-Relationship Diagram (ERDs): An entity relationship diagram is a


graphical representation of entities and their relationships to each other.

Elements of Entity Relationship Diagram: Different elements of E-R


diagram are as follows;

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

STUDENT COUNTRY CAR

Entity Instance: A single occurrence of an entity is called Entity Instance. For


example, an Entity Instance of Entity STUDENT is;
Roll No Name Class Age Address
1 Kaleem 1st Year 16 Bannu

10
COMPUTER SCIENCE NOTES (ICS_PART-I)

Attribute: The property or characteristics of an entity is called Attribute. For


example, Roll No, Name, Age, Class, Address of a student are his attributes. In
ERD, Attributes are represented by ‘Oval’ shape.

ROLL NO

Relationship: A meaningful association/connection between different entities


is called a Relationship. It describes that how data is shared b/w entities. The
entities that participate in a relationship are called Participants. In ERD,
Relationship is represented by ‘Diamond’ shape.

___________________________*****xxxxx*****________________________

Explain the degree of a Relationship with examples?


The number of participating entities in a relationship is known as the degree of
the relationship.

Types: It has three (3) types;


• Unary Relationship
• Binary Relationship
• Ternary Relationship

Unary Relationship: A type of relationship that is established within a single


entity is called Unary Relationship. It is also known as Recursive Relationship.

TEACHER Works
with

Binary Relationship: A type of relationship that is established between two


entities is called Binary Relationship.

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)

One-To-One: In One-To-One relationship, one instance of an entity ‘A’ is


associated with only one instance of another entity ‘B’. For example, one
country has one president.

COUNTRY Has PRESIDENT

One-To-Many: In One-To-Many relationship, one instance of an entity ‘A’ is


associated with many instances of another entity ‘B’ but for one instance of
entity ‘B’ there is only one instance of entity ‘A’. For example, one college can
have many departments but one department is part of only one college.

COLLEGE Has DEPARTMENTS

Many-To-Many: In Many-To-Many relationship, one instance of entity ‘A’ is


associated with many instances of entity ‘B’ and one instance of entity ‘B’ is
associated many instances of entity ‘A’. For example, one student may study
many courses and one course may be studied by many students.

STUDENT Studies COURSE

Ternary Relationship: A type of relationship that is established among three


entities is called Ternary Relationship. For example, one or many analysts works
with one or many programmers on one or many projects.

ANALYST Works PROGRAMMER


on

PROJECT

___________________________*****xxxxx*****________________________

12
COMPUTER SCIENCE NOTES (ICS_PART-I)

What is Key in a database? Discuss different types of Keys used in a


database?
Key: An attribute or set of attributes that uniquely identifies each record in a
table is called a Key. It’s also called an Identifier. For example, Student’s Roll No,
Employee Id, Customer No etc are key fields.

Types of Keys: There are different types of keys.


• Super Key
• Candidate Key
• Primary Key
• Alternate Key
• Composite Primary Key
• Foreign Key
• Secondary Key
Super Key: An attribute or set of attributes that uniquely identifies each record
in a relation is called Super Key. For example, attribute Roll No and Reg_No is
Super Key. Any combination of attribute with super key is also a super key. For
example [Roll No, Name] is also a super key.
Candidate Key: A Candidate key is a super key that contains no extra attributes.
It consists of minimum possible attributes. For example [Roll No, Name] is a
super key but only Roll No is a Candidate key.
Primary Key: A candidate key that uniquely identifies each record in a relation is
called Primary key. For Example, Roll No, Reg_No, Student Id etc.
Some important points about a 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.
Alternate Key: The candidate keys that are not selected as primary key is called
Alternate Key. For example, the attributes Roll No and Reg_No can be used to
identify each student in the table. If Roll No is selected as Primary key then
Reg_No is known as Alternate key.
Composite Primary Key: A Primary key that consists of two or more attributes is
known as Composite Primary Key. For Example, the attributes [Roll No, Subject]
in a Marks table identify each record.
Foreign Key: A foreign key is an attribute in a relation whose values match a
primary key in another table. The table containing the foreign key is known as
dependent table or child table and the table to which the foreign key refers is
known as parent table or referenced table.

13
COMPUTER SCIENCE NOTES (ICS_PART-I)

Student ID Name Class Course ID


st
101 Kaleem 1 Year C001
102 Qasim 1st Year C002
103 Afran 1st Year C003

Foreign Key
Primary Key
Course ID Course Name
C001 Computer
C002 Physics
C003 Math

___________________________*****xxxxx*****________________________

What is Cardinality and Modality in a database?


Cardinality: The maximum number of instances of one entity that may be
associated with each instance of another entity is known as Cardinality.
Cardinality can be 1 or many and the symbol is placed on the outside ends of the
relationship line, closest to the entity.

Modality: The minimum number of instances of one entity that may be


associated with each instance of another entity is known as Modality.
Modality can be 1 or 0 and the symbol is placed inside of the relationship line,
next to cardinality symbol.

A circle  indicates that relationship is optional. A stroke  indicates that


relationship is mandatory and the maximum number of relationships is one. A
crow-foot indicates that many relationships between instances of the related
entities may exist.
The following diagram indicates all of the possible combinations:

14
COMPUTER SCIENCE NOTES (ICS_PART-I)

___________________________*****xxxxx*****________________________

Draw an ERD for the following systems?


1. Library Management System
2. Student Management System
3. Ticket Booking System
4. Hospital Management System
Library Management System: In Library Management System, the following
entities and attributes can be identified.

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

Relationship: The following relationships will be established among all the


entities.
i. The relationship b/w Publisher and Book is one-to-many because a
Publisher publishes many books.
ii. The relationship b/w Member and Book is also one-to-many because a
Member can borrow one or more books.

E-R Diagram for Library Management System

Price Available Address Price


Title

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)

Student Management System: In the Student Management System, the


following entities and attributes can be identified.

Department: The set of all the departments in an organization. Each


department has the following attributes;
• Department_ID
• Department Name
• Location

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

Relationship: The following relationships will be established among all the


entities.
i. The relationship b/w Department and Course is one to many because a
department offers many courses for study.
ii. The relationship b/w Department and Teacher is one to many because
there are many teachers in a department to teach different courses.
iii. The relationship b/w Teacher and Course is one to many because a Teacher
teaches one or many courses.
iv. The relationship b/w Student and Course is many-to-many because a
Student can study one or more courses and a Course can be taken one or
more students.

17
COMPUTER SCIENCE NOTES (ICS_PART-I)

E-R Diagram for Student Management System

Address
Dept_ID
Class

Name STUDENT DEPARTMENT


Dept_Name
M 1 1
Student_ID
Location
Study

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.

Airline: It is a set of all airlines and its attributes are;


• Airline_Code
• Airline Name

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

Relationship: The following relationships will be established among all the


entities.
i. The type of relationship b/w Airline and Flight is one-to-many because one
airline has many flights.
ii. The type of relationship b/w Passenger and Seat is one-to-one because
each passenger books a single seat.
iii. The type of relationship b/w Flight and Passenger is one-to-many because
each flight has many passengers.
iv. The relationship b/w Flight and Seat is one-to-many because there may be
one or many seats available in each flight.

E-R Diagram for Ticket Booking System

Airline_Code Ticket No

AIRLINE PASSENGER
Name
1 N R1
Name
Addres
s
Flies Phone
Flight_No

Books
Arrival Date N 1

Arrival Time FLIGHT


1

Departure Date Class


N Seat_No
Departure Time 1
N
Name
SEAT

19
COMPUTER SCIENCE NOTES (ICS_PART-I)

Hospital Management System: In Hospital Management System, the


following entities and attributes can be identified.

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

Relationship: The following relationships will be established among all the


entities.
i. The relationship b/w Doctor and Patient is one-to-many because a single
doctor treats many patients at a time.
ii. The relationship b/w Patient and Medicine is many-to-many because
different patients pay bills for different medicines.

20
COMPUTER SCIENCE NOTES (ICS_PART-I)

E-R Diagram for Hospital Management System

Specialization
Qualification

Name DOCTOR
1

Doctor_ID

Treats

N
Patient_ID
PATIENTM
Medicine_Code
N
Address

Quantity

Age N
Price
MEDICINE

___________________________*****xxxxx*****________________________

What is a Relational Schema? Describes different steps of


Transformation of E-R Model into Relational Schema?
Relational Schema: A relational schema is the tables, columns and
relationships that make up a relational database. The schema describes that how
real-world entities are modeled in the database. A relational schema helps the
users to organize and understand the structure of a database.

Transformation of E-R Model into Relational Schema: To transform E-R


model into Relational schema, the following tasks will be performed.

1. Transform Entities into Relational Schema: Each entity is replaced by a


relation. Each relation has a unique name. Each relation has a number of rows
and columns. Each row refers to an entity instance and each column refers to an
attribute.

2. Transform Attributes into Relational Schema: Each attribute is


replaced by a column (field) in the relation. All the attributes of an entity will
become columns (fields) of a table.

3. Transform Relationships into Relational Schema: Each relationship in


E-R model must also be represented in relational schema. The representation
21
COMPUTER SCIENCE NOTES (ICS_PART-I)

depends upon the type of relationship. For example, a relationship is


represented by making the primary key of one relation and foreign key of
another relation but sometimes a separate relation is created for a relationship.
Example:
Name
Roll No

STUDENT

Class Address

Roll No Name Class Address


101 Kaleem 1st Year Mamash Khel
102 Hasnain 1st Year Mamash Khel
103 Qasim 1st Year Mamash Khel

___________________________*****xxxxx*****________________________

What is Functional Dependency? Explain Partial Dependency and


Transitive Dependency with examples?
Functional dependency: Functional Dependency is a relationship between
attributes. It means that if the value of one attribute is known, it is possible to
obtain the value of another attribute. A functional dependency is denoted by an
arrow →. The functional dependency of X on Y is represented by;
X→Y
Determinant Dependent
It means that attribute ‘Y’ is dependent on attribute ‘X’ because ‘X’ determines
each value of ‘Y’.

Partial Dependency: Partial Dependency occurs when a secondary key


attribute (non-primary key) is functionally dependent on part of a composite
primary key.

Example: ‘Score Table’


Score_ID Student_ID Subject_ID Marks Teacher

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)

The attribute ‘Teacher’ only depends on Subject_ID, not on Student_ID, so this


is a Partial Dependency.

Student_ID + Subject_ID → Teacher

Transitive Dependency: When a secondary key is dependent on a Primary


key as well as on a non-Primary key attribute then such dependency is called
Transitive Dependency.
OR
A functional dependency is said to be transitive if it is indirectly formed by two
functional dependencies.

Primary Key → Non-Primary Key → Secondary Key

If X → Y → Z Then X → Z

Example: ‘Employee Table’


Emp_ID Name Hours Job Class
1 Ahmad 12 Civil Engineer
2 Ali 20 Electrical Engineer
3 Asif 18 Software Engineer

Emp_ID → Job Class → Hours


Emp_ID → Hours

___________________________*****xxxxx*****________________________

What is Normalization? Explain 1NF, 2NF and 3NF with example?


Normalization: The process of producing a simpler and more reliable database
structure is called Normalization.
OR
The process of converting a complex database structure into simple database
structure is called Normalization.
OR
The step-by-step process of analyzing the functional dependencies among the
attributes of a relation is called Normalization.
OR
The step-by-step process of splitting the entity types is called Normalization.

23
COMPUTER SCIENCE NOTES (ICS_PART-I)

Purposes of Normalization: The purposes of normalization are as follows:


✓ Eliminating redundant (useless) data.
✓ Eliminating functional dependencies.
✓ Eliminating insertion, deletion and updation anomalies.

Un-Normalized Form: If a Relation contain one or more repeating groups


then it is called Un-Normalized Form (UNF) and the Relation is called Un-
Normalized Relation.

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

Normal Form: The degree of normalization is termed as Normal Form. For


Example;
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)

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.

Second Normal Form (2NF): A Relation is said to be in 2NF, if it satisfied the


following rules.
1. It should be in 1st Normal Form.
2. It should not have any Partial Dependency.
In the ‘Employee’ table, the attribute Proj_Name is dependent on Proj_No,
while Emp_Name, Job_Class and Charge_Per_Hour are dependent on Emp_No.
These are Partial Dependencies that should be removed. So, we will split the
‘Employee’ Table as given below;
‘Employee Table’
Partial Dependency Partial Dependency

Proj_No Proj_Name Emp_No Emp_Name Job_Class Charge_Per_Hour Hours

‘Employee Table’

Emp_No Emp_Name Job_Class Charge_Per_Hour

‘Hours Table’ ‘Project Table’


Proj_No Emp_No Hours Proj_No Proj_Name

Third Normal Form (3NF): A Relation is said to be in 3NF, if it satisfied the


following rules.
1. It should be in a 2NF.
2. It should not have any Transitive Dependency.
In the ‘Employee’ table, the attribute Charge_Per_Hour is dependent on non-
key attribute Job_Class and attribute Job_Class is dependent on Primary key
attribute Emp_No which creates a Transitive Dependency that should be
removed. So, we will split the ‘Employee’ Table as given below;

25
COMPUTER SCIENCE NOTES (ICS_PART-I)

‘Employee Table’

Transitive Dependency

Emp_No Emp_Name Job_Class Charge_Per_Hour

‘Employee Table’ ‘Job Table’


Emp_No Emp_Name Job_Class Job_Class Charge_Per_Hour

X
AJAB NOOR
Lecturer in Computer Science, GPGC Bannu

26

You might also like