Lecture 02
Lecture 02
Lecture 02
USING ER DIAGRAMS
Prof. Koliya Pulasinghe
OBJECTIVES
• Data Modelling using ER Model
CONCEPTUAL MODELING
ER DIAGRAMS
• Many versions of ER-diagrams; differ
both in their appearance and in their
meaning
• We will use the version appearing in the
book (Database Management Systems
by Elmasri Navathe)
• Have a formal semantics (meaning) that
must be thoroughly understood, in order
to create correct diagrams
ENTITY-RELATIONSHIP
(ER) MODEL
Requirements gathering
WEAK ENTITY
RELATIONSHIP
IDENTIFYING
RELATIONSHIP
ATTRIBUTE
KEY ATTRIBUTE
E-R NOTATION
SYMBOL MEANING
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
E1 R E2 TOTAL PARTICIPATION OF E2 IN R
E1
1
R
N
E2 CARDINALITY RATIO 1:N FOR
E1:E2 IN R
R
(min,max)
E
STRUCTURAL CONSTRAINT (min,
max) ON PARTICIPATION OF E IN R
ENTITY
• Graphically,
ENTITY STUDENT
Name
• BOC is the largest bank network having over 5,000 branches and over
500,000 customers. Customers can open accounts in any bank branch.
• Identify
• Entities
• At least 3 attributes /entity
SLIIT STUDENT
REGISTRATION
New students are required to produce their national ID
card number, name, address, age, date of birth and
gender during the registration process. they are also
required to select the degree program of their choice.
The programs are selected based on the entry criteria,
specialty, duration, fees etc.
• Entity ?
• Attributes ?
ENTITY SET
Example: name, id, age & salary are attributes in Employee entity
Salary
salary name
e1
age id
e2 Age
e3 EMPLOYEE
e4
e5 Id
e6
…
Name
Employee Entity set
EXAMPLE
Name Manf
JUICE
Graphically,
Name EMPLOYEE
Surname Middle_name
First_name
YOUR TURN!!
STUDENT
E-mail
Surname First_name
Employee
age
name
Derived attribute
AN EXERCISE
stuNu stuName stuMajor stuDob stuHrs stuYr stuGpa stuAge
m
stuName
stuMajor
stuDob
stuHrs
stuYr
stuGpa
stuAge
KEY ATTRIBUTES
• key attribute - Minimal set of attributes which
uniquely identify an entity in the entity set.
Underlined
salary name
e1
age id
e2
e3
e4
e5
e6
…
Employee Entity set
PRIMARY KEY
Employee
Candidate
eid nic
key
COMPOSITE KEY
• Example :
Composite key = (student no + Unit Number +
ST ID Unit ID Marks
marks)
IT1601 IT103 85
IT1601 IT104 78
IT1602 IT103 72
IT1603 IT104 82
SUPER KEY
• Any other set of attributes that uniquely identify a tuple is
called the superkey of a relation
Student ( SID, Name, Address, Contact, GPA)
student gender
courseNo
studentID dob
course coursename
fee
duration faculty
RELATIONSHIP
• Relationship is an association among two or more entities.
• Collection of similar relationships - relationship set .
• Shown as a line connecting the associated entities, labelled with
the name of the relationship.
N 1
Student registers Course
relationship
EXAMPLE:
RELATIONSHIPS
Drinkers frequent
some bars.
name Drinker addr
DEGREE OF A RELATIONSHIP
N 1
Student registers Course
relationship
DEGREE OF RELATIONSHIP
• = no of participating entities
• Relationships can be classified based on their degree into
• Binary – relationship with two participants-
Degree/No of Entities = 2
• Ternary – relationship with three participants
Degree/No of Entities = 3
• Quaternary – relationship with four participants
Degree/No of Entities = 4
TERNARY RELATIONSHIPS
Preferences
Drinker
name addr
TERNARY RELATIONSHIP
name
Location
name dname
ssn lot did budget
12-233 D10
12-354 •
•
D12
12-243
• D13
12-299 • Rome
London
Paris
CARDINALITY
• one-to-one (1: 1)
• one-to-many (1 : N)
• many-to-many. (N : M)
ONE-TO-ONE RELATIONSHIP
N 1
Employee Works in Department
N 1
Drinker Favorite Juice
YOUR TURN !!
M N
Employee Works on Project
EXAMPLE: MANY - MANY
RELATIONSHIP
since
startdate
N 1
Employee Works in Department
1/2/99
e011 1/2/09
HR
e022
1/5/01
Sales
e033 1/2/07
Marketing
e044
1/3/05
Departments
Employees
Work_in
ATTRIBUTE ON RELATIONSHIP
price
• Determine
• Cardinality
Registe
Student Course
• N r 1
PARTICIPATING CONSTRAINTS
Participation Constraint
Student?
WEAK ENTITY
• Parents employed?
• Does the company cover THE CHILDRENS medical insurance?
• How do you claim your medical bills
• Can you get it reimbursed or through your parents
• Is the same coverage given to children after resignation
WEAK ENTITY
1 M
Employee covers Dependent
age
age Double lined
idid name
box
Partial key
WEAK ENTITY
• Some entities can’t exist on its own.
• Its’ existence-dependent on another entity, i.e., it cannot exist
without the entity with which it has a relationship.
• It inherits the part of the primary key from the entity to which it is
related.
• Entity types without any key attributes is called weak entity types.
• The attributes in the weak entity participating in the key are
called partial keys.
address
atmID since transac# amount
type
1 N
ATM facilitates Transactions
RECURSIVE
RELATIONSHIP
• Have you formed your project groups
• What is the structure?
• Leader and members
1 N
Leader Leads Member
X
• Both leader and members are students
1 N
Student Leads Student
E-R MODEL (CONTD.)
Student leads set of students in group
assignments.
leads
Student
RECURSIVE
RELATIONSHIP
• Entities participating in a relationship need not be distinct. Such
relationships are called recursive relationships.
X
1 supervis N
Manager Employee
e
salar salar
y Job y Job
tittle tittle
eno name
1 Manager
supervis
Employee
e
salar
y Job N Subordinates
tittle
YOUR TURN !
(1,1)
(0,1)
1 1
(0,N)
(1,1)
N 1
Employee must(NN
work for a department. .
A department may or may not have any employee
ENHANCED ER MODELLING
• ER modelling does not capture all the
semantics of client’s domain, such as
• ‘ISA’ (‘is a’) relationship or specialization-
generalization
• ‘Manager’ entity type ‘is a’ sub entity of
‘Staff’ entity.
Staff Specialization/generalization
indicator
Hours worked
Contract_ duration
Hourly rate