Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 42

IS273: Database Systems

Spring 2020

Data Modeling and the


Entity-Relationship Model
Three Stages of
Database Development
• Requirements Analysis Stage
• Component Design Stage
• Implementation Stage
The Requirements Analysis Stage

• Sources of requirements
– User Interviews
– Forms
– Reports
– Queries
– Use Cases
– Business Rules
Requirements Become the
E-R Data Model
• After the requirements have been
gathered, they are transformed into
an Entity Relationship (E-R) Data
Model
• E-R Models consist of
– Entities
– Attributes
– Identifiers
– Relationships
Why Learn About Database
Modeling?
• The way in which data is stored is very important
for subsequent access and manipulation by SQL.

• Properties of a good data model:


– It is easy to write correct and easy to understand
queries.
– Minor changes in the problem domain do not
change the schema.
– Major changes in the problem domain can be
handled without too much difficulty.
– Can support efficient database access.
Purpose of E/R Model
• The E/R model allows us to sketch the design
of a database.
– Represent different types of data and how they
relate to each other
• Designs are pictures called entity-relationship
diagrams.
• Fairly mechanical ways to convert E/R
diagrams to real implementations like
relational databases exist.
Entity Sets
• Entity= Entity instance = “thing” or object.
– An entity instance is a specific occurrence of an entity
within an entity class
• Entity set= Entity class = collection of similar entities.
– An entity class is a description of the structure and
format of the occurrences of the entity
– Similar to a class in object-oriented languages.

7
Entity Sets instructor and student

instructor_ID instructor_name student-ID student_name


Entity Class and Entity Instance
Attributes
• Attribute = property of an entity set.
– Generally, all entities in a set have the same
properties.
– Attributes are simple values, e.g. integers or
character strings.
• As an example, attributes that describe
the entity (projects)
– ProjectName
– StartDate
– ProjectType
– ProjectDescription
Level of Entity Attribute Display
Identifiers
• Entity instances have identifiers
• An identifier will identify a particular
instance in the entity class
– SocialSecurityNumber
– StudentID
– EmployeeID
Identifier Types
• Uniqueness
– Identifiers may be unique or non-unique
– If the identifier is unique, the data value for the
identifier must be unique for all instances
• Composite
– A composite identifier consists of 2 or more
attributes
• E.g., OrderNumber & LineItemNumber are both
required
Relationships
• A relationship connects two or more
entity sets.
• Relationship degree defines the
number of entity classes participating
in the relationship
– Degree 2 is a binary relationship
– Degree 3 is a ternary relationship
Degree 2 Relationship:
Binary
Relationship Set advisor
Degree 3 Relationship:
Ternary
Relationship Set
• The current “value” of an entity set is
the set of entities that belong to it.
– Example: the set of all cafes in our
database.
• The “value” of a relationship is a set
of lists of currently related entities,
one from each of the related entity
sets.
Example
• A relationship R between entity sets E and F
relates some entities in E to some entities in F.
• R is a set of pairs of tuples (e, f ) where e is in E
and f is in F.
• For the relationship Sells, we might have a
relationship set like:
cafe drink
Joe’s cafe coke
Joe’s cafe pepsi
Sue’s cafe coke
Sue’s cafe apple juice
Sue’s cafe coke Lite
Multiway Relationships
• Sometimes, we need a relationship
that connects more than two entity
sets.
• Suppose that drinkers will only drink
certain drinks at certain cafes.
– Our three binary relationships Likes,
Sells, and Frequents do not allow us to
make this distinction.
– But a 3-way relationship would.
Example
name addr name manf

license cafes drinks

Preferences

Drinkers

name addr
A Typical Relationship Set

cafe Drinker drink


Joe’s cafe Ann pepsi
Sue’s cafe Ann coke
Sue’s cafe Ann apple juice
Joe’s cafe Bob coke
Joe’s cafe Bob pepsi
Joe’s cafe Cal pepsi
Sue’s cafe Cal coke Lite
Entity-Relationship Diagrams
– Entity classes (Entity set) are shown by rectangles
– Relationships are shown by diamonds
– Each attribute of an entity set is represented by an
oval, with a line to the rectangle representing its
entity set.
– The maximum cardinality of the relationship is
shown inside the diamond
– The minimum cardinality is shown by the oval or
hash mark next to the entity
– The name of the entity is shown inside the
rectangle
– The name of the relationship is shown near the
diamond
Example
name manf

drinks

• Entity set drinks has two attributes, name


and manf (manufacturer).
• Each drink entity has values for these two
attributes, e.g. (coke, Anheuser-Busch)
Example

name addr name manf


cafes sell some
drinks.

cafes Sells drinks

license

Note: Drinkers like


Frequents Likes
license = some drinks.
drink, full,
none

Drinkers
name addr

Drinkers frequent
some cafes.
Multiplicity of E/R Relations

• one-one:
1 a
2 b
3 c
d
• many-one
1 a
2 b
3 c
d
• many-many
1 a
2 b
3 c
d
Representing “Multiplicity”
• Show a many-one relationship by an
arrow entering the “one” side.
• Show a one-one relationship by arrows
entering both entity sets.
• In some situations, we can also assert
“exactly one,” i.e., each entity of one set
must be related to exactly one entity of the
other set. To do so, we use a rounded
arrow. (Referential Integrity will be
discussed later)
One-to-One Relationship
• one-to-one relationship between an instructor and a
student
– an instructor is associated with at most one student via advisor
– and a student is associated with at most one instructor via
advisor
One-to-Many Relationship
• one-to-many relationship between an instructor and a
student
– an instructor is associated with several (including 0) students
via advisor
– a student is associated with at most one instructor via advisor,
Many-to-One Relationships
• In a many-to-one relationship between an instructor and a
student,
– an instructor is associated with at most one student via advisor,
– and a student is associated with several (including 0) instructors
via advisor
Many-to-Many Relationship
• An instructor is associated with several (possibly 0)
students via advisor
• A student is associated with several (possibly 0)
instructors via advisor
Maximum Cardinality
• Relationships are named and classified by
their cardinality, which is a word that
means count
• Each of the three types of binary
relationships shown above have different
maximum cardinalities
• maximum cardinality is the maximum
number of entity instances that may
participate in a relationship instance—
one, many or some other fixed number
Minimum Cardinality
• Minimum cardinality is the
minimum number of entity instances
that must participate in a relationship
instance
• These values typically assume a
value of zero (optional) or one
(mandatory)
Cardinality Example
• Maximum cardinality is many for both
ITEM and SUPPLIER
• Minimum cardinality is zero (optional) for
ITEM and one (mandatory) SUPPLIER
– A SUPPLIER does not have to supply an
ITEM
– An ITEM must have a SUPPLIER
Attributes on Relationships
• Sometimes it is useful to attach an
attribute to a relationship.
• Think of this attribute as a property of
tuples in the relationship set.

cafes Sells drinks

price

Price is a function of both the cafe and the drink,


not of one alone.
Attributes on Relationships
• 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
Roles in Relationships
• Can the same entity set appear more than
once in the same relationship?
• Prerequisite relationship between two
Courses

• Which course is the pre-requisite?


Roles in Relationships
• Label the edges between the
relationship and the entity set with
names called roles.
Subclasses in E/R Diagrams
• A subclass entity is a special case of another entity called
its superclass (Subclass = fewer entities = more
properties).
• The identifier of a superclass and all of its subclasses
types is the same attribute
• An attribute of the superclass may be included which
indicates which of the subclass is appropriate for a given
instance—This attribute is called a discriminator
• Subclasses can be exclusive or inclusive
– If exclusive, the superclass relates to at most one subclass
– If inclusive, the superclass can relate to one or more
subclasses
Subclasses in E/R Diagrams
• Isa triangles indicate the subclass
relationship.
– Point to the superclass.
• Assume subclasses form a tree.
– i.e., no multiple inheritance.
Example
• Juices are a kind of drink.
– Not every drink is a juice, but some are.
– Let us suppose that in addition to all the
properties (attributes and relationships) of
drinks, juices also have the attribute fruit.

name drinks manf

isa

fruit Juices
Examples

You might also like