ER Model
Dr. Jenila Livingston L.M.
SCSE
1
Entity-Relationship Modelling
1. Entities
2. Attributes
3. Relationships
4. Constraints
Keys
Mapping Cardinality
5. ER Notations
6. Roles
7. Participation
8. Strong & Weak Entity Sets
2
Entity-Relationship (ER) Modeling.
1976 proposed by Peter Chen
ER diagram is widely used in database design
Represent conceptual level of a database system
Describe things/entities and their relationships in high level
1/9/2020 3
3
ER Modeling.
ER Modeling is a top-down approach to
database design.
Entity Relationship (ER) Diagram
A detailed, logical representation of the entities,
associations and data elements for an organization
or business
Notation uses three main constructs
Data entities
Chen Model &
Relationships Crow’s Foot Model
Attributes
4
ER Diagrams
Several ER diagramming techniques have been proposed over the years:
Chen’s notation - 1976
IDEF1X (NIST) - 1993
Crow’s feet (Barker, Palmer, Ellis, et al.) – 1981
UML (Booch, Jacobson and Rumbaugh) – 1990’s
Others…
The authors current version is somewhat UML-like, but previously used Chen’s
notation.
5
Chen Notation
Association
between the
instances of one or
more entity types
EntityName Verb Phrase AttributeName
Person, place, object, event named property or
or concept about which data characteristic of an
is to be maintained entity
Represents a set or collection of
objects in the real world that
share the same properties
6
Crow’s Foot Notation
Entity Attribute Relationship
EntityName
EntityName Verb phrase
List of
Attributes
7
1. Entities
Examples of entities:
Person: EMPLOYEE, STUDENT, PATIENT
Place: STORE, WAREHOUSE
Object: MACHINE, PRODUCT, CAR
Event: SALE,REGISTRATION, RENEWAL
Concept: ACCOUNT, COURSE
Guidelines for naming and defining entity types:
An entity type name is a singular noun
An entity type should be descriptive and specific
An entity name should be concise
Event entity types should be named for the result of the event, not
the activity or process of the event.
8
2. Attributes
Example of entity types and associated attributes:
STUDENT: Student_ID, Student_Name, Home_Address,
Phone_Number, Major
Guidelines for naming attributes:
An attribute name is a noun.
An attribute name should be unique
To make an attribute name unique and clear, each attribute name
should follow a standard format
Similar attributes of different entity types should use similar but
distinguishing names.
9
Attributes
The set of permitted values for an attribute is call the domain of that attribute.
Attributes can be one of several types:
Simple (i.e., atomic) – height in inches, weight in ounces, last-name
Composite – name, address
Single-valued – date of birth, name
Multi-valued – phone-numbers, dependents, hobbies
Derived – “age” is derived, or rather, computed from “date-of-birth”
10
Composite Attributes
11
Attributes - Chenn
12
13
Attributes - UML
composite
customer
simple ID
name
first
middle
last
address
strieet
number
name
apt-number
city multi-valued
derived state
zip-code
{ phone_number }
date-of-birth
age ()
Notes:
In many applications the terms are much more ambiguous (e.g., function designators)
An ER diagram is typically accompanied by a document that defines all the terms
Much harder to do than it appears (e.g., what is an “orbit” for a satellite?)
14
3. Relationships
Associations between instances of one or more entity types that is of interest
Given a name that describes its function.
• relationship name is an active or a passive verb.
Relationship name:
writes
Author Book
An author writes one or more books
A book can be written by one or more authors.
15
Relationships
Lecturer handles Class
Member Searches Books
16
Relationships
since
name dname
ssn lot did budget
Employees Works_In Departments
Relationship: Association among two or more entities. E.g., Bob Smith
works in Pharmacy department.
relationships can have their own attributes.
Verb or Verb phrases (e.g., works_at, enrolled_in, etc)
Relationship Set: Collection of similar relationships.
An n-ary relationship set R relates n entity sets E1 ... En ; each
relationship in R involves entities e1 E1, ..., en En
17
Degree of Relationships
Degree: number of entity types that participate in a relationship
Three cases
Unary: between two instances of one entities
Binary: between the instances of two entities
Ternary: among the instances of three entities
N-nary: among the instances of more than three entities
18
E-R Diagram with a Ternary Relationship
19
Relationship
An attribute can also be property of a relationship set.
For instance, the advisor relationship set between entity sets
instructor and student may have the attribute date which
tracks when the student started being associated with the
advisor
20
Relationship Sets with Attributes
access-date
customer
account
ID depositor number
name balance
strieet
city
21
4. Constraints
Keys
Cardinalities
22
Keys
Entities and relationships are distinguishable using various keys
A key is a combination of one or more attributes, e.g., social-security
number, combination of name and social-security number.
A primary key of an entity set is specified in an ER diagram by
underlining the key attributes.
customer
loan
ID borrower number
name amount
strieet
city
23
Mapping Cardinalities
The mapping cardinality of a relationship set expresses the number of
entities to which one entity can be associated via the relationship set.
Most useful in describing binary relationship sets.
For a binary relationship there are four types:
One to one
One to many
Many to one
Many to many
24
Cardinalities Examples
25
Mapping Cardinalities
One to one One to many
Note: Some elements in A and B may not be mapped to any
elements in the other set
26
Mapping Cardinalities
Many to one Many to many
Note: Some elements in A and B may not be mapped to any
elements in the other set
27
Mapping Cardinalities
affect Attribute Placement
In the banking enterprise, access-date could be an attribute of account
instead of a relationship attribute if each account can have only one
customer, i.e., if the relationship is one-to-many.
28
Cardinality Constraints
Cardinality constraints are indicated by drawing a directed line (),
signifying “one,” or an undirected line (—), signifying “many,” between
the relationship and the entity.
If borrower were a one-to-one relationship:
A customer would be associated with at most one loan
n loan would be associated with at most one customer
customer
loan
ID borrower number
name amount
strieet
city
29
One-To-Many Relationship
If borrower were a one-to-many relationship from customer to loan, then
a customer would be associated with zero or more one loans, and a
loan would be associated with at most one customer.
customer
loan
ID borrower number
name amount
strieet
city
30
Many-To-One Relationships
If borrower were a many-to-one relationship from customer to loan, then
a loan would be associated with zero or more customers, and a
customer would be associated with at most one loan.
customer
loan
ID borrower number
name amount
strieet
city
31
Many-To-Many Relationship
If borrower were a many-to-many relationship then a customer would be
associated with zero or more loans, and a loan would be associated with
zero of more customers.
customer
loan
ID borrower number
name amount
strieet
city
32
5. ER NOTATIONS – Chenn Model
33
ER Notations
1. Rectangles divided into two parts represent entity sets.
The first part, contains the name of the entity set. The
second part contains the names of all the attributes of the
entity set.
2. Diamonds represent relationship sets.
3. Undivided rectangles represent the attributes of a
relationship set.
Attributes that are part of the primary key are underlined.
4. Lines link entity sets to relationship sets.
5. Dashed lines link attributes of a relationship set to the
relationship set.
6. Double lines indicate total participation of an entity in a
relationship set.
7. Double diamonds represent identifying relationship sets
linked to weak entity sets
34
ER Notations - Revised
Rectangles - entity sets
Diamonds - relationship sets
Lines - connect attributes to entity sets, and entity sets to relationship sets.
Underlined Attributes – primary key attributes
customer
loan
ID borrower number
name amount
strieet
city
35
ER Notations
36
ER Notations
37
6. Roles
The function that an entity plays in a relationship is called
its role.
Entity sets of a relationship need not be distinct
Each occurrence of an entity set plays a “role” in the relationship
The labels “course_id” and “prereq_id” are called roles.
38
Roles
Worker and Manager both
are 2 roles of Employee
1. Director
2. Manager
3. Secretary
4. Worker
39
7. Participation of an Entity Set
in a Relationship Set
If every entity in an entity set must participate in a relationship set, then
that entity set is said to have total participation in the relationship;
indicated by a double-line and a double-diamond.
customer
loan
ID borrower number
name amount
strieet
city
If participation in a relationship is optional for some entities then that
entity set is said to have partial participation in the relationship.
All elements of loan participate in customer
40
8. Strong Entity Sets
For most entity sets, a primary key is specified in terms of its immediate
attributes.
Such an entity set is referred to as a strong entity set.
41
Weak Entity Sets
An entity set that does not have a primary key is referred to
as a weak entity set.
They are dependent on another entity
The existence of a weak entity set depends on the existence
of a identifying entity set
It must relate to the identifying entity set via a total, one-to-many
relationship set from the identifying to the weak entity set
Identifying relationship depicted using a double diamond
The discriminator (or partial key) of a weak entity set is the
set of attributes that distinguishes among all the entities of a
weak entity set.
42
Weak Entity Sets, Cont.
In such a case, the (weak) entity typically has a subset of attributes,
called a discriminator (or partial key), that distinguishes among all
entities of the weak entity set associated with one identifying entity.
In such a case, a primary key for the weak entity set can be constructed
with two parts:
primary key of the strong entity set on which the weak entity set is
existence dependent
The weak entity set’s discriminator
A weak entity set is typically associated with an identifying entity
set (which is usually strong) via a total, one-to-many relationship.
43
Weak Entity Sets (Cont.)
A weak entity set is represented by double rectangles.
The discriminator is underlined with a dashed line.
44
More Weak Entity Set Examples
In a university, a course is a strong entity and a section can be modeled as
a weak entity.
course
section
ID sec-course sec_id
title semester
credits year
The discriminator of section would be sec-id, semester and year.
If section were modeled as a strong entity then it would have id as an
attribute; the relationship with course would be implicit in the id attribute.
45
E-R Diagram for a Banking
Enterprise (Chen’s Notation)
46
E-R Diagram
for a University
47
Exercise -1
Draw an ER diagram that best represents the
following situation. There are three types of
accounts in a bank, with these attributes:
• Checking: Acct-no, Date-opened, Balance,
Service-charge
• Savings: Acct-no, Date-opened, Balance,
Interest-rate
• Loan: Acct-no, Date-opened, Balance, Acct-limit
48
Exercise 2
A company database needs to store information about employees
(identified by ssn, with salary and phone as attributes), departments
(identified by dno, with dname and budget as attributes), and
children of employees (with name and age as attributes).
Employees work in departments; each department is managed by
an employee
Draw an ER diagram that captures this information and the following.
• Identify the primary keys and foreign keys
• Apply all types of attributes wherever it can be used.
• Apply mapping cardinalities and participation constraints
49
Thank You!
50