Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Lesson07 e r modelling
1. 6 September 2019 S M Irteza / Dr Rafi Ullah 1
Lesson 07 E-R Modeling
Entity Relationship Modeling
2. 6 September 2019 S M Irteza / Dr Rafi Ullah 2
E-R Model
Benefits:
1. Provides the big picture (Macro View) of an
organization’s data requirements and relationships.
Normalization is micro view of the database or the
table
2. Helpful in communicating with managers and end
users.
3. E-R model is concurrently used with normalization
process
3. 6 September 2019 S M Irteza / Dr Rafi Ullah 3
E-R Model Components & E-R Diagram
1) Entities: (tables)
Regular Entities
Weak Entities
Their existence is dependent on some other entity
in the sense that it cannot exist if that other entity
does not also exists.
E.g.
Employee Department
4. 6 September 2019 S M Irteza / Dr Rafi Ullah 4
E-R Model Components & E-R Diagram
2) Attributes
Denoted by an oval shape, they are of 2 basic types:
Simple or composite
Base or derived
Does not exists with in a database , instead it is derived
by using an algorithm etc.
5. 6 September 2019 S M Irteza / Dr Rafi Ullah 5
Employee
ENAME
L-name
MID-
Name
FNAME DOB
Salary
AGE
EMP#
Simple
Attribute Derived
Attribute
Dotted line shows the derived attributes
e.g. age = System clock - DOB
Composite
attribute
6. 6 September 2019 S M Irteza / Dr Rafi Ullah 6
E-R Model Components & E-R Diagram
3) Relationships:
An Association among entities represented by diamond
shaped symbol in E-R Diagram.
CONNECTIVITY:
Is used to describe the relationship classification such as
1. One To One
2. One To Many
3. Many To Many
7. 6 September 2019 S M Irteza / Dr Rafi Ullah 7
Examples
Example:
as many profs. Might be in one department. But if one
professor can belong to many departments then ,
1 M
hasDept Professors
M M
hasDept Professors
8. 6 September 2019 S M Irteza / Dr Rafi Ullah 8
Examples
e.g.
e.g.
Must see from both point of views….. !!!
1 1
hasCountry President
M M
ShipsSupplier Parts
9. 6 September 2019 S M Irteza / Dr Rafi Ullah 9
Examples
e.g
M M
hasStudent Courses
10. 6 September 2019 S M Irteza / Dr Rafi Ullah 10
E-R Model Components & E-R Diagram
4) ENTITY SUPER-TYPE AND SUB-TYPE
Entities can be represented in a hierarchy.
The super type entity is composed of several disjoint
(non-overlapping) sub-type entities.
Super type is usually broken down into several sub
types.
Attributes that apply to the super type can be inherited
by the sub type.
11. 6 September 2019 S M Irteza / Dr Rafi Ullah 11
ENTITY SUPER-TYPE AND SUB-TYPE
Employee
DOB Salary
Address
Name
AccountantProgrammer
Field
App. Prog. Sys. Prog.
Specialty
Language
Disjoint
12. 6 September 2019 S M Irteza / Dr Rafi Ullah 12
Transforming Entities And Attributes Into
Relations (tables)
A Set of transformation rules
One To One
One To Many
Many To Many
13. 6 September 2019 S M Irteza / Dr Rafi Ullah 13
One To One
1 1
hasCountry President
Population
CapitalName
DOB
Name Salary……
……
14. 6 September 2019 S M Irteza / Dr Rafi Ullah 14
One To One
How will we connect the two tables?
The P.K of president appears in Country table as a F.K
Or, the P.K of Country Appears in the President as a F.K
Or BOTH
Country President
Name Population Capital
Pakistan 200,121,234 Islamabad
Iran 35,635,456 Tehran
India 1,156,311,334 New Delhi
Yemen 23,000,000 Sana’a
Name DOB Education
Asif Zardari 26/7/1955 B.Sc
Ahmedinejad 28/10/1956 PhD
Pratibha Patel 19/12/1934 MS, LLB
Ali Abdullah Saleh 1/2/1945 B.Sc
15. 6 September 2019 S M Irteza / Dr Rafi Ullah 15
One To One
Name Population Capital GMI
Usa 12342323 Washington 12354
Pak 121234 Islamabad 1234
Aus 35635456 Sydney 12453
Ind 4563334 Madras 2355
…. ….. …… …..
Country President
F.KP.K
Name DOB Education C_Name
Asif Zardari 26/7/1955 B.Sc Pakistan
Mahmood
Ahmedinejad
28/10/1956 PhD
Iran
Pratibha Patel 19/12/1934 MS, LLB
India
Ali Abdullah Saleh 1/2/1945 B.Sc
Yemen
16. 6 September 2019 S M Irteza / Dr Rafi Ullah 16
One To Many
1 M
hasDept Professors
Chairman
BudgetName
S#
Name Office……
……
17. 6 September 2019 S M Irteza / Dr Rafi Ullah 17
One To Many
How to represent the relation b/w these two tables having
one to many relationship?
MANY side of the relationship must include the P.K of
ONE side as a F.K.
Integrity Rules must Hold
If ‘Bio’ is deleted from Dept, all entries in Prof for ‘Bio’
are Deleted.
Name Chair Budget Sect
CS Prof. X 124334 Ms. abc
Math Prof. Y 23423 Ms. J
Acc Prof. Z 234 Mr. G
Bio Prof. S 23423 Mr. Kol
…. ….. …… …..
Dept
PName S# Office Phone
Pervez 1930 … …
Bashir 1950 … …
Boota 1940 … …
Mali 1920 … …
Bush 1800 … …
Prof
18. 6 September 2019 S M Irteza / Dr Rafi Ullah 18
One To Many
Name Chair Budget Sect
CS Prof. X 124334 Ms. abc
Math Prof. Y 23423 Ms. J
Acc Prof. Z 234 Mr. G
Bio Prof. S 23423 Mr. Kol
…. ….. …… …..
Dept
PName S# Office Phone Dept
Prof. Y 1 … … CS
Prof Z 2 … … Math
Prof X 3 … … CS
Prof A 4 … … Bio
Prof. X 3 … … Phy
Prof
F.KP.K
19. 6 September 2019 S M Irteza / Dr Rafi Ullah 19
Many To Many
M M
hasSuppliers Parts
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
P# PNAME COLOR WEIGHT CITY
P1 Nut Red 12 London
P2 Bolt Green 17 Paris
P3 Screw Blue 17 Rome
P4 Screw Red 14 London
P5 Cam Blue 12 Paris
P6 Cog Red 19 London
Parts P
20. 6 September 2019 S M Irteza / Dr Rafi Ullah 20
Many To Many
In M-to-M , cases adding one more attribute does NOT
work, we must create another Table.
The relationship needs a table of its own called
BRIDGE IDENTITY.
New Table is composed of P.K of the connected entities
and it may also include additional attributes.
M M
SPSuppliers Parts
BRIDGE IDENTITY
21. 6 September 2019 S M Irteza / Dr Rafi Ullah 21
Many To Many
The Shipment table contains both P.K from the two
previous tables.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
P# PNAME COLOR WEIGHT CITY
P1 Nut Red 12 London
P2 Bolt Green 17 Paris
P3 Screw Blue 17 Rome
P4 Screw Red 14 London
P5 Cam Blue 12 Paris
P6 Cog Red 19 London
Parts P
S# P# QTY
S1 P1 300
S1 P2 200
S1 P3 400
S1 P4 200
S1 P5 100
S1 P6 100
S2 P1 300
S2 P2 400
S3 P2 200
S4 P2 200
S4 P4 300
S4 P5 400
Shipment SP
P.K
P.K
F.K for table PF.K for table S
22. 6 September 2019 S M Irteza / Dr Rafi Ullah 22
Many To Many
Student(SS# , Name…)
Enrollment(SS# , Course# , Grade)
Classes(Course# , Date , Classroom)
So We use a Bridge entity for joining two tables
having M to M relationship.
M M
EnrollsStudent Classes
BRIDGE IDENTITY
23. 6 September 2019 S M Irteza / Dr Rafi Ullah 23
Example
Professor
Student
Dept
Classes
Offers
Has
Employee
Chair
Teaches
Advises
Enrolls
24. 6 September 2019 S M Irteza / Dr Rafi Ullah 24
1. So we have to build 5 tables
2. Then Normalize the tables.
Profes
sor
Student
Dept
Class
es
Offers
Has
Employee
Chair
Teaches
Advise
s
Enrolls
25. 6 September 2019 S M Irteza / Dr Rafi Ullah 25
END
END
(slides taken from M Ali Shahid’s original slides)