You are on page 1of 56

Chapter 5

Entity Relationship (E-R)


Modeling
Basic Modeling Concepts
• Database design is both art and science.

• A data model is the relatively simple


representation, usually graphic, of
complex real-world data structures. It
represents data structures and their
characteristics, relations, constraints, and
transformations.

• The database designer usually employs


data models as communications tools to
facilitate the interaction among the
designer, the applications programmer,
and the end user.
Data Models: Degrees of Data
Abstraction
Figure 2.10 page 57
The Conceptual Model
• The conceptual model represents a global view
of the data. It is an enterprise-wide
representation of data as viewed by high-level
managers.
– Entity-Relationship (E-R) model is the most
widely used conceptual model.
– The conceptual model forms the basis for the
conceptual schema.
– The conceptual schema is the visual
representation of the conceptual model.
– The conceptual model is independent of both
software (software independence) and
hardware (hardware independence).
Tiny College Entities

Figure 2.11 Page 58


A Conceptual Schema for Tiny College

Figure 2.12 Page 59


The Internal Model

– The internal model adapts the


conceptual model to a specific DBMS.

– The internal model is software-


dependent.

– Development of the internal model is


especially important to hierarchical and
network database models.
Figure 2.13 Page 61
Figure 2.13 Page 61
The External
Model/Schema

• The external model is the end user’s


view of the data environment.
– Each external model is then
represented by its own external
schema.
CREATE VIEW CLASS_VIEW AS
SELECT (CLASS_ID, CLASS_NAME,
PROF_NAME, CLASS_TIME, ROOM_ID)
FROM CLASS, PROFESSOR, ROOM
WHERE CLASS.PROF_ID =
PROFESSOR.PROF_ID AND CLASS.ROOM_ID
= ROOM.ROOM_ID;
Extern
al
Model

Extern
al
Model

Figure 2.14 Page 63


The External
Model/Schema
Advantages of Using External Schemas
• It makes application program
development much simpler.
• It facilitates the designer’s task by
making it easier to identify specific
data required to support each business
unit’s operations.
• It makes the designer’s job easier by
providing feedback about the
conceptual model’s adequacy.
• It helps to ensure security constraints
The Physical Model
– The physical model operates at the
lowest level of abstraction, describing the
way data is saved on storage media such
as disks or tapes.
– It requires the definition of both the
physical storage devices and the access
methods required to reach the data
within those storage devices.
– The physical model is both software and
hardware-dependent.
– It requires detailed knowledge of
hardware and software used to
Entity Relationship (E-R)
Model
• E-R model is commonly used to:
– Translate different views of data
among managers, users, and
programmers to fit into a
common framework.
– Define data processing and
constraint requirements to help
us meet the different views.
– Help implement the database.
Entity Relationship (E-R)
Model
• E-R Model Components
– Entities
• In E-R models an entity refers to the entity set.
• An entity is represented by a rectangle
containing the entity’s name.
– Attributes
• Attributes are represented by ovals and are
connected to the entity with a line.
• Each oval contains the name of the attribute it
represents.
• Attributes have a domain -- the attribute’s set of
possible values.
• Attributes may share a domain.
• Primary keys are underlined.
– Relationships
Attributes of the STUDENT Entity

Figure 4.1 Page 125


Basic E-R Model Entity Presentation

Figure 4.3 Page 127


The CLASS Table (Entity)
Components and Contents

Figure 4.2 Page 126


Classes of
Attributes
• A simple attribute cannot be subdivided.
• Examples: Age, Sex, and Marital
status
• A composite attribute can be further
subdivided to yield additional attributes.
• Examples:
– ADDRESS - Street, City, State, Zip
– PHONE NUMBER - Area code,
Exchange number
Classes of
Attributes
• Asingle-valued attribute can have only a
single value.
• Examples:
– A person can have only one social
security number.
– A manufactured part can have only one
serial number.

• Multivalued attributes can have many


values.
• Examples:
– A person may have several college
degrees.
– A household may have several phones
with different numbers
Splitting the Multivalued Attributes
into New Attributes

Figure 4.4 Page 128


A New Entity Set Composed of
Multivalued Attribute’s Components

Figure 4.5 Page 129


Derived Attributes
– A derived attribute is not physically stored
within the database; instead, it is derived by
using an algorithm.
• Example: AGE can be derived from the data
of birth and the current date.

Figure 4.6 Page 130

Emp_Age = Current Date - Emp_DOB


Relationship
• A relationship is an association between
entities.
• Relationships are represented by diamond-
shaped symbols.

Figure 4.7 Page 132


Relationship Degree
• A relationship’s degree indicates the
number of associated entities or
participants.
– A unary relationship exists when an
association is maintained within a single
entity.
– A binary relationship exists when two
entities are associated.
– A ternary relationship exists when three
entities are associated.
Relationship Degree

Figure 4.16 Page 143


The Implementation
of a Ternary
Relationship

Figure 4.17 Page 144


Connectivity
• Connectivity
– The term connectivity is used to describe
the relationship classification (e.g., one-
to-one, one-to-many, and many-to-many).

Figure 4.7 Page 132


Cardinality
• Cardinality
– Cardinality expresses the specific number
of entity occurrences associated with one
occurrence of the related entity.

Figure 4.7 Page 132


Existence
Dependency

• If an entity’s existence
depends on the existence
of one or more other
entities, it is said to be
existence-dependent.
Weak Relationship

Figure 4.9 Page 134

Class will not exist if course does not exist.


Class depends on Course
Relationship
Participation
• The participation is optional if one
entity occurrence does not require a
corresponding entity occurrence in a
particular relationship.
• An optional entity is shown by a small
circle on the side of the optional
entity.

Figure 4.11 Page 137


CLASS is Optional to COURSE

Figure 4.12 Page 138


COURSE and CLASS in a Mandatory
Relationship

Figure 4.13 Page 139


Weak Entities
• Weak Entities
– A weak entity is an entity that
• Is existence-dependent and
• Has a primary key that is partially or
totally derived from the parent entity
in the relationship.
– The existence of a weak entity is
indicated by a double rectangle. The
weak entity inherits all or part of its
primary key from its strong
counterpart.
A Weak Entity in an ERD

Figure 4.14 Page 140


Weak Relationship Between
DEPENDENT and EMPLOYEE

Figure 4.15 Page 141


Recursive Entities
• Recursive Entities
– A recursive entity is one in which a
relationship can exist between
occurrences of the same entity set.
– A recursive entity is found within a
unary relationship.

Figure 4.18 Page 145


Recursive Entities

Figure 4.19 Page 145

1. James Ramirez is married to Louise Ramirez, who is


married to
James Ramirez
2. Anne Jones is married to Anton shapiro, who is married to
Anne
Jones
Recursive Entities

Figure 4.20 Page 146

A rotor assembly is composed of four 2.5cm washers,


two cotter pins, one 2.5 cm steel shank, four 10.25cm
rotor blades, and two 2.5 cm hex nuts
The Implementation of the M:N Recursive
“PART Contains PART” Relationship

Figure 4.21 Page 146


Implementation of the M:N “COURSE
Requires COURSE” Recursive
Relationship

Figure 4.22 Page 147


Implementation of the 1:M “EMPLOYEE
Manages EMPLOYEE” Recursive
Relationship

Figure 4.23 Page 147


Composite Entities
• A composite entity is composed of the
primary keys of each of the entities to be
connected.
– The composite entity serves as a bridge
between the related entities.
– The composite entity may contain
additional attributes.
The M:N Relationship Between
STUDENT and CLASS

Figure 4.25 Page 149


A Composite Entity in the ERD

Figure 4.26 Page 149


Converting the M:N Relationship
Into Two 1:M Relationships

Figure 4.24 Page 148


Entity Supertypes and Subtypes

Figure 4.27 Page 150


Entity Supertypes and Subtypes

• The generalization hierarchy depicts the


parent-child relationship.
– The supertype contains the shared
attributes, while the subtype contains
the unique attributes.
– A subtype entity inherits its attributes
and its relationships from the supertype
entity.
A Generalization Hierarchy

Figure 4.28 Page 151


Entity Supertypes and Subtypes
• Entity Supertypes and Subtypes
– The supertype entity set is usually
related to several unique and
disjointed (nonoverlapping) subtype
entity sets.
– The supertype and its subtype(s)
maintain a 1:1 relationship.
The EMPLOYEE/PILOT
Supertype/Subtype Relationship

Figure 4.29 Page 152


Entity Supertypes and Subtypes

• Entity Supertypes and Subtypes


– The generalization hierarchy depicts
the parent-child relationship. (Figure
4.34)
– The supertype contains the shared
attributes, while the subtype contains
the unique attributes.
– The supertype entity set is usually
related to several unique and
disjointed (nonoverlapping) subtype
A Generalization Hierarchy
With Overlapping Subtypes

Figure 4.30 Page 153


References

• ROB, P. AND CORONEL, C., 2004, Database


Systems. 6th Ed., Thomson Course Technology

You might also like