Data Modeling using the Entity-
Relationship (ER) model
Chapter 3
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
1
Outline
n Overview of Database Design Process
n Example Database Application (COMPANY)
n ER Model Concepts
n Entities and Attributes
n Entity Types, Value Sets, and Key Attributes
n Relationships and Relationship Types
n Weak Entity Types
n Roles and Attributes in Relationship Types
n ER Diagrams - Notation
n ER Diagram for COMPANY Schema
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
2
Overview of Database design process
n Two main activities:
n Database design
n Applications design
n Focus in this chapter on database design
n To design the conceptual schema for a database
application
n Applications design focuses on the programs and
interfaces that access the database
n Generally considered part of software engineering
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
3
Domains, attributes, tuples and relations…
Example: company database
n We need to create a database schema design
based on the following (simplified) requirements
of the COMPANY Database:
n The company is organized into DEPARTMENTs.
Each department has a name, number and an
employee who manages the department. We keep
track of the start date of the department manager.
A department may have several locations.
n Each department controls a number of PROJECTs.
Each project has a unique name, unique number
and is located at a single location.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
4
Example: company database
n We store each EMPLOYEE’s social security
number, address, salary ...
n Each employee works for one department but may
work on several projects.
n We keep track of the number of hours per week that
an employee currently works on each project.
n We also keep track of the direct supervisor of each
employee.
n Each employee may have a number of
DEPENDENTs.
n For each dependent, we keep track of their name,
sex, birthdate, and relationship to the employee.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
5
ER Model concepts
n Entities and Attributes
n Entities are specific objects or things in the mini-world that
are represented in the database.
n For example the EMPLOYEE John Smith, the Research
DEPARTMENT, the ProductX PROJECT
n Attributes are properties used to describe an entity.
n For example an EMPLOYEE entity may have the attributes
Name, SSN, Address …
n A specific entity will have a value for each of its attributes.
n For example a specific employee entity may have Name='John
Smith', SSN='123456789', Address ='731, Fondren, Houston,
TX’, BirthDate='09-JAN-55‘
n Each attribute has a value set (or data type) associated with
it – e.g. integer, string, subrange, enumerated type, …
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
6
Types of attributes
n Simple
n Each entity has a single atomic value for the attribute. For
example: SSN.
n Composite
n The attribute may be composed of several components. For
example:
n Address(Apt#, House#, Street, City, State, ZipCode, Country), or
n Name(FirstName, MiddleName, LastName).
n Composition may form a hierarchy where some components
are themselves composite.
n Multi-valued
n An entity may have multiple values for that attribute. For
example, Color of a CAR or Previous Degrees of a STUDENT.
n Denoted as {Color} or {Previous Degrees}.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
7
Example of composite attributes
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
8
Entity, types and key attributes
n Entities with the same basic attributes are
grouped or typed into an entity type.
n For example, the entity type EMPLOYEE
and PROJECT.
n An attribute of an entity type for which each
entity must have a unique value is called a
key attribute of the entity type.
n For example, SSN of EMPLOYEE.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
9
Entity, types and key attributes
n A key attribute may be composite.
n VehicleTagNumber is a key of the CAR entity
type with components (Number, State).
n An entity type may have more than one key.
n The CAR entity type may have two keys:
n VehicleIdentificationNumber (popularly called VIN)
n VehicleTagNumber (Number, State), aka license
plate number.
n Each key is underlined
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
10
Displaying an entity type
n In ER diagrams, an entity type is displayed in a
rectangular box
n Attributes are displayed in ovals
n Each attribute is connected to its entity type
n Components of a composite attribute are
connected to the oval representing the composite
attribute
n Each key attribute is underlined
n Multivalued attributes displayed in double ovals
n See CAR example on next slide
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
11
Entity cars with two keys and a correspondi
ng entity set
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
12
Entity set
n Each entity type will have a collection of entities
stored in the database
n Called the entity set
n Previous slide shows three CAR entity instances
in the entity set for CAR
n Same name (CAR) used to refer to both the entity
type and the entity set
n Entity set is the current state of the entities of that
type that are stored in the database
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
13
Initial design of entity types for the company
database schema
n Based on the requirements, we can identify four
initial entity types in the COMPANY database:
n DEPARTMENT
n PROJECT
n EMPLOYEE
n DEPENDENT
n Their initial design is shown on the following slide
n The initial attributes shown are derived from the
requirements description
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
14
Initial design of entity types:
EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
15
Refining the initial design by introducing
relationship
n The initial design is typically not complete
n Some aspects in the requirements will be
represented as relationships
n ER model has three main concepts:
n Entities (and their entity types and entity sets)
n Attributes (simple, composite, multivalued)
n Relationships (and their relationship types and
relationship sets)
n We introduce relationship concepts next
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
16
Refining the initial design by introducing
relationship
n A relationship relates two or more distinct entities with a
specific meaning.
n For example, EMPLOYEE John Smith works on the ProductX
PROJECT, or EMPLOYEE Franklin Wong manages the
Research DEPARTMENT.
n Relationships of the same type are grouped or typed into a
relationship type.
n For example, the WORKS_ON relationship type in which
EMPLOYEEs and PROJECTs participate, or the MANAGES
relationship type in which EMPLOYEEs and DEPARTMENTs
participate.
n The degree of a relationship type is the number of
participating entity types.
n Both MANAGES and WORKS_ON are binary relationships.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
17
Relationship instances of the n:1
Relationship between EMPLOYEE and DEPARTMENT
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
18
Relationship instances of the m:n
Relationship between EMPLOYEE and PROJECT
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
19
Relationship type Vs Relationship set
n Relationship Type:
n Is the schema description of a relationship
n Identifies the relationship name and the
participating entity types
n Also identifies certain relationship constraints
n Relationship Set:
n The current set of relationship instances
represented in the database
n The current state of a relationship type
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
20
Relationship type Vs Relationship set
n Previous figures displayed the relationship sets
n Each instance in the set relates individual
participating entities – one from each participating
entity type
n In ER diagrams, we represent the relationship
type as follows:
n Diamond-shaped box is used to display a
relationship type
n Connected to the participating entity types via
straight lines
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
21
Refining the COMPANY database
Schema by introducing relationships
n By examining the requirements, six relationship types are
identified
n All are binary relationships( degree 2)
n Listed below with their participating entity types:
n WORKS_FOR (between EMPLOYEE, DEPARTMENT)
n MANAGES (also between EMPLOYEE, DEPARTMENT)
n CONTROLS (between DEPARTMENT, PROJECT)
n WORKS_ON (between EMPLOYEE, PROJECT)
n SUPERVISION (between EMPLOYEE (as subordinate),
EMPLOYEE (as supervisor))
n DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
22
ER Diagram – Relationship types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION, DEPENDTS_OF
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
23
Discussion on Relationship types
n In the refined design, some attributes from the initial entity
types are refined into relationships:
n Manager of DEPARTMENT -> MANAGES
n Works_on of EMPLOYEE -> WORKS_ON
n Department of EMPLOYEE -> WORKS_FOR
n etc
n In general, more than one relationship type can exist
between the same participating entity types
n MANAGES and WORKS_FOR are distinct relationship types
between EMPLOYEE and DEPARTMENT
n Different meanings and different relationship instances.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
24
Recursive relationship type
n An relationship type whose with the same participating
entity type in distinct roles
n Example: the SUPERVISION relationship
n EMPLOYEE participates twice in two distinct roles:
n supervisor (or boss) role
n supervisee (or subordinate) role
n Each relationship instance relates two distinct EMPLOYEE
entities:
n One employee in supervisor role
n One employee in supervisee role
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
25
Weak entity types
n An entity that does not have a key attribute
n A weak entity must participate in an identifying relationship type with
an owner or identifying entity type
n Entities are identified by the combination of:
n A partial key of the weak entity type
n The particular entity they are related to in the identifying entity type
n Example:
n A DEPENDENT entity is identified by the dependent’s first name,
and the specific EMPLOYEE with whom the dependent is related
n Name of DEPENDENT is the partial key
n DEPENDENT is a weak entity type
n EMPLOYEE is its identifying entity type via the identifying
relationship type DEPENDENT_OF
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
26
Constraints on relationships
n Constraints on Relationship Types
n (Also known as ratio constraints)
n Cardinality Ratio (specifies maximum participation)
n One-to-one (1:1)
n One-to-many (1:N) or Many-to-one (N:1)
n Many-to-many (M:N)
n Existence Dependency Constraint (specifies minimum
participation) (also called participation constraint)
n zero (optional participation, not existence-dependent)
n one or more (mandatory participation, existence-dependent)
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
27
Many-to-one (N:1) Relationship
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
28
Many-to-many (M:N) Relationship
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
29
Displaying a recursive relationship
n In a recursive relationship type.
n Both participations are same entity type in
different roles.
n For example, SUPERVISION relationships
between EMPLOYEE (in role of supervisor or
boss) and (another) EMPLOYEE (in role of
subordinate or worker).
n In following figure, first role participation labeled
with 1 and second role participation labeled with
2.
n In ER diagram, need to display role names to
distinguish participations.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
30
A Recursive Relationship Supervision
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
31
Recursive Relationship Type is: SUPERVISION
(participation role names are shown)
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
32
Attributes of Relationship types
n A relationship type can have attributes:
n For example, HoursPerWeek of WORKS_ON
n Its value for each relationship instance describes
the number of hours per week that an EMPLOYEE
works on a PROJECT.
n A value of HoursPerWeek depends on a particular
(employee, project) combination
n Most relationship attributes are used with M:N
relationships
n In 1:N relationships, they can be transferred to the
entity type on the N-side of the relationship
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
33
Example Attribute of a Relationship Type:
Hours of WORKS_ON
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
34
Notation for Constraints on Relationships
n Cardinality ratio (of a binary relationship): 1:1,
1:N, N:1, or M:N
n Shown by placing appropriate numbers on the
relationship edges.
n Participation constraint (on each participating
entity type): total (called existence dependency)
or partial.
n Total shown by double line, partial by single line.
n NOTE: These are easy to specify for Binary
Relationship Types.
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
35
Alternative (min, max) notation for relations
hip structural constraints:
n Specified on each participation of an entity type E in a relationship
type R
n Specifies that each entity e in E participates in at least min and at
most max relationship instances in R
n Default(no constraint): min=0, max=n (signifying no limit)
n Must have min ≤ max, min ≥ 0, max ≥ 1
n Derived from the knowledge of mini-world constraints
n Examples:
n A department has exactly one manager and an employee can
manage at most one department.
n Specify (0,1) for participation of EMPLOYEE in MANAGES
n Specify (1,1) for participation of DEPARTMENT in MANAGES
n An employee can work for exactly one department but a
department can have any number of employees.
n Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
n Specify (0,n) for participation of DEPARTMENT in WORKS_FOR
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
36
The (min,max) notation for relationship
constraints
Read the min, max numbers next to the entity
type and looking away from the entity type
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
37
COMPANY ER Schema Diagram using (min,
max) notation
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
38
Summary of notation for ER diagrams
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
39
Relationships of higher degree
n Relationship types of degree 2 are called binary
n Relationship types of degree 3 are called ternary
and of degree n are called n-ary
n In general, an n-ary relationship is not equivalent
to n binary relationships
n Constraints are harder to specify for higher-
degree relationships (n > 2) than for binary
relationships
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
40
Example of a ternary relationship
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
41
Another example of a ternary relationship
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
42
Displaying constraints on higher-degree rela
tionships
n The (min, max) constraints can be displayed on the edges
– however, they do not fully describe the constraints
n Displaying a 1, M, or N indicates additional constraints
n An M or N indicates no constraint
n A 1 indicates that an entity can participate in at most one
relationship instance that has a particular combination of the
other participating entities
n In general, both (min, max) and 1, M, or N are needed to
describe fully the constraints
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
43
Summary
n ER Model Concepts: Entities, attributes,
relationships
n Constraints in the ER model
n Using ER in step-by-step conceptual schema
design for the COMPANY database
n ER Diagrams – Notation
Chapter
3:
The
rela7onal
data
model
and
the
Fundamentals
of
Database
rela7onal
constraints
44