Chapter-02 With Normalization
Chapter-02 With Normalization
Chapter-02 With Normalization
Parent
Child
Hierarchical
e.g. In this model each entity has only one parent but can have
Model
several children . At the top of hierarchy there is only one entity
which is called Root.
Cont
d.
►A parent element have many child
elements but a child element
cannot have many parent
elements.
► That is this model cannot
represent many to many
relationship.
Advantages of Hierarchical
Model
► 1. It is simple & natural method
of implementing record
relationship.
► 2. It is useful when there is some
hierarchical character in
the database.
Disadvantag
► 1 This es cannot
model all
. relationship
represent that occur in world
the
► 2.Itreal
cannot represent many .to
relationshi many
► 3 p.Insert Anomaly : It is not possible
. insert
to data about new
► dependent.
4.Delete Deletio in this
Anomaly
leads to: nof manymodel
loss
info rmation. necessary
► 5. Update Anomaly : Updation
operation leads several inconsistencies.
Network
Model
► In network model data is
represented by records using
links among them, which can
be viewed as pointers.
► Network model is many to
many (M : M) , Many to One
(M : 1), One to one (1 : 1)
relationship model.
e.g
.
Custome Product
r Table
Table
Order Order
Table
Table
Network
e.g. In the network model, entities are organized in a graph, in
Model which some
entities can be accessed through several path
Advantages of Network
Model
► 1.This model is useful representing
for such records which many
have many
► relationship.
2. Problem of Inconsistency todoes
not exist in this model.
► 3. Searching of records is easy
because there are multiple
access paths.
Disadvantages of Network
Model
► All the records are maintained using
pointers and hence the whole
database structure becomes very
complex.
► Insertion, deletion and updation of any
record would require pointer
adjustments.
2.2 Record Based(Relational
Model )
► In a Relational Database Model, data is
organized in the form of rows and
columns similar to table.
► Tables are referred as relations in
this model.
► Rows are referred as tuples.
► Columns are referred as Attributes.
Cont
d.
► A relational is defined as
model
database that allowsa you to group
its data items into one or more
independent tables that can be
related to one another by using
fields common to each related
table.
Relational
e.g. In this model, data is organized in two- dimensional tables called
Model relations.
The tables or relation are related to each other.
Advantages of Relational
Model
► This model can be efficiently used
with limited main memory &
Processing capability.
► Relational database model is only
concerned with data & not with
structures, which improves the
performance.
► Instead of pointers Record
relationship
is implemented, hence it is very
simple.
2.2. Object Based Database
►Model
Object Oriented database are dependent
on the
object oriented programming
paradigm.
► This model creates classes, objects,
structures, call methods.
► Designed to store, retrieve & Manage
objects created by programs written in
language like C++ or Java.
► Designed to provide object oriented
facilities to users of languages like C or
Pascal.
Object Based Database
Model
Advantages of
► This
OOD
model work on Nested
Structure applications which is
complex in the form of objects
instead of tables and records.
► i.e. : CAD/CAM, aerospace science.
► Relational database have only limited
data types like integer, char, text,
but OOD allow arbitrary data
types and sub classing.
5. Distributed Data
► In
Model
a distributed system communication
& exchange of data among one
another is a main facility.
► Data Sharing : User operating on one
computer can work on any another
computer.
► Distributed Control: Responsibility of
control is divided among local
administrator.
► Reliability & Availability : Even if one site
fail, the remaining sites can continue
working.
2.4 Representation of Entities, attributes,
relationship attributes, relationship set
Entity
Attributes
Relationship
Key attributes
24
ENTITY
Students
26
Weak & Strong Entity
Students
27
Strong Entity
roll-no class
Students
28
ENTITY SET
29
Attributes
31
Simple and Composite Attribute
32
Composite Attributes
Customer 35
Null attribute
36
Key Attribute
37
KEYS
39
Candidate Key
A Candidate key is an attribute that uniquely identifies a
record.
candidate key is a column in a table which has the
ability to become a primary key.
e.g. For account entity acc_no is candidate key. If
combination of cust_name and branch_name is sufficient
to distinguish among members of the account then
(cust_name, account_number, branch-name) is also a
candidate key.
acc_no cust_name branch_name
Candidate Key 40
Primary Key
The primary key identifies every record in
table uniquely and must never be the same
for two records.
The primary key should be chosen such that its
attributes are never, or very rarely changed.
Address field of a person should not be a
part of the primary key. Since it is likely to
change.
Emp_code are Primary key which
guaranteed to never change.
41
Composite Key
A key formed by the combination of 2 or
more columns is the composite key.
A composite Key can be either Primary or
Unique Key. More then One Key columns
are said to be composite keys
When a record cannot be uniquely
identified by a single field, in such case a
composite key is used. e.g.
Supplier_id Part_id
Composite Key 42
Foreign Key
An attribute or combination of attribute in a
table whose value match a primary key in
another table.
The purpose of the foreign key is to
ensure referential integrity of the data. e
e.g.
Prod_code Prod_name Supp_code
Foreign Key
Supp_code Supp_name
43
Notation for E-R Diagram
Symbol Meaning
44
Notation for E-R Diagram
Symbol Meaning
Ellipses Which represents
Attributes
Which link attributes
Lines to entity sets &
entity sets to
relationship sets.
Ellipse with Which represent key
Line attribute
45
Contd.
Symbol Meaning
Double Ellipses Which represent
multi-valued
attributes
Dashed ellipses Which denote
double lines derived
attributes
46
Relationships
47
Contd.
48
One-to-one Relationship (1 : 1)
1
Department HOD
1
49
One-to-Many Relationship (1 : M)
1
Father Children
M
50
Many-to-Many Relationship (M:M)
M
Customer Item
M
51
One-To-Many Relationship
52
Many-To-One Relationships
53
Many-To-Many Relationship
54
E-R Diagram with different Attributes
Middle-name last-name
First-name
name Composite
Attribute
customer-id
Customer
Multivalued attributes Derived
Attribute
phone- age
date-of-birth
Number
55
Weak Entity Sets
56
Attribut
ERD:- es
Stat Cit
e y Entity sets
Customer Customer
_State Loan_ Amou
_name nt
number
Customer
Customer
_id
_City
61
E-R Diagram for Insurance Company
Insurance Customer
member customer_add
company
company_ad owns
d
Car
No. of
car name Car no. accidents
63
2. E-R Diagram for Banking Enterprise
Employee
Branch
Loan
Payment
Account 64
E-R Diagram for a Banking Enterprise
65
E-R Diagram for Practice
66
Cont..
67
E-R Diagram
Tes Examination ID
ID Name t
Appoint Treatme
nt
Doctors
Name
Specialization
Reg.No.
68
E-R Diagram for Practice
69
E-R Diagram for Practice
70
E-R Diagram
Student Register
s
Course
Student Ph.No
71
Tables of E-R Diagram
1. Student table
Stud roll Stud name Stud Stud Phone No.
no. Address
integer Character Character Number
2. Course
table Course name Fee
Character Number
72
SPECIALISATION
73
Specialization (Top Down Process)
Specialization is the result of taking
subsets of a higher level entity set to
form lower level entity sets.
Specialization is the process of
defining a set of subclasses of an
entity type.
Specialization is the top down
process.
74
Contd.
For example, Specialization of Employee
entity.
Attributes of Employee Entity.
emp_id, emp_name, emp_dob,
emp_name
emp_id emp_dob
employee
75
Contd.
A employee may be further classified
as one of the following
Teaching
Non-teaching
Each of these employee types is
described by a set of attributes that
includes all the attributes of entity
set employee plus possibly additional
attributes.
76
Contd.
i.e. Teaching entity be described
may
further by the attribute emp_vacation,
where as No teaching entity may be
described further by the attribute emp_EL.
The Process of designating sub
groupings within an entity set is called
Specialization.
The specialization of employee allows us
to distinguish among employee according
to whether they are Teaching or Non-
Teaching. 77
Contd.
employee
ISA
emp_EL
emp_vacation
Teaching Non-Teaching
Owne Pressur
r Plan e
t
Specialized
as
Owne Locatio
r n
Plan
t
ISA
80
Generalization
Generalization is the result of taking the
union of several lower level entity sets to
produce higher-level entity set.
(The UNION operator returns results from both queries after
eliminating duplication)
Generalization is the exact
reverse process of Specialization.
Generalization is Bottom-Up Process.
Generalization is used to emphasize
the similarities among lower-level
and to hide the
entity differences.
sets 81
Contd.
For example : There is similarities between
saving account entity set and current account
entity set in bank account.
They have several attributes in common.
This commonality can be expressed by
Generalization.
Interest_rate Name
Name Acc_no overdraft_amt
Acc_no
acc_no name
Account
ISA
overdraft_amt
Interest_rate
Numb nam
er e
Vehicle
IS
A
85
Contd..
Job
Manage
s
Manager
ER-Diagram with 8
Aggregation 6
Database normalization
All the entries are atomic and there is a composite primary key (employee_id,
job_code) so the table is in the first normal form (1NF).
But even if you only know someone's employee_id, then you can determine
their name, home_state, and state_code (because they should be the same
person). This means name, home_state, and state_code are dependent
on employee_id (a part of primary composite key). So, the table is not in 2NF.
We should separate them to a different table to make it 2NF.
Example of Second Normal Form (2NF)
employee_id job_code
E001 J01
E001 J02
E002 J02
E002 J03
E003 J01
job_code job
J01 Chef
J02 Waiter
J03 Bartender
To take this a step further, we should separate them again
to a different table to make it 3NF.
employee_roles Table
employee_id job_code
employees Table
E001 J01
E001 J02 employee_id name state_code
E002 J02
E001 Alice 26
E002 J03
E003 J01 E002 Bob 56
E003 Alice 56
job_code job
J01 Chef state_code home_state
J02 Waiter
26 Michigan
J03 Bartender
56 Wyoming
SUMMARY
Specialization is the result of
taking a subset of higher level
entity set to form a lower level
entity set.
Generalization is the result of
taking the union of two or more
lower level entity sets to produce
higher level entity set.
90
SPPU-Questions
1) Explain generalization and aggregation-Oct-2012- 10
2) Explain Various key in relational data models –Ap-
2012-10
3) Explain Various constraints in relational models-Oct-
2012-10.
91