2 Er
2 Er
• Network
• Relational
• Object oriented
• Object Relational
Business Rules (enforce
Constraints)
• Brief, precise, and unambiguous description
of a policy, procedure, or principle within a
specific organization’s environment
10
Entity Sets
11
Attributes
16
Example
name manf
drinks
17
Relationships
• A relationship connects two or more entity
sets.
• It is represented by a diamond, with lines to
each of the entity sets involved.
18
Example
license
Drinkers
name addr
Drinkers frequent
some cafes. 19
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.
20
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.
21
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.
22
Example
name addr name manf
Preferences
Drinkers
name addr
23
A Typical Relationship Set
24
Many-Many Relationships
• Think of a relationship between two entity
sets, such as Sells between cafes and drinks.
• In a many-many relationship, an entity of
either set can be connected to many entities
of the other set.
– E.g., a cafe sells many drinks; a drink is sold by
many cafes.
25
Many-One Relationships
• Some binary relationships are many -one from
one entity set to another.
• Each entity of the first set is connected to at
most one entity of the second set.
• But an entity of the second set can be
connected to zero, one, or many entities of
the first set.
26
Example
• Favorite, from Drinkers to drinks is many-one.
• A drinker has at most one favorite drink.
• But a drink can be the favorite of any number
of drinkers, including zero.
27
One-One Relationships
28
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.
29
Example
Favorite
30
Example
• Consider Best-seller between Manfs and
drinks.
• Some drinks are not the best-seller of any
manufacturer, so a rounded arrow to Manfs
would be inappropriate.
• But a manufacturer has to have a best-seller
(we assume they are drink manufacturers).
31
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.
price
34
Example
Relationship Set
Husband Wife
Bob Ann
Joe Sue
… …
Married
husband wife
Drinkers
35
Example
Relationship Set
buddy1 buddy2
Bob Ann
Joe Sue
buddies Ann Bob
Joe Moe
… …
1 2
Drinkers
36
Parallel Relationships
• Can there be more than one relationship between
the same pair of entities?
• TA and Take relationship between Students and
Classes
37
Subclasses
• Subclass = special case = fewer entities = more
properties.
• 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.
38
Subclasses in E/R Diagrams
• Assume subclasses form a tree.
– i.e., no multiple inheritance.
• Isa triangles indicate the subclass relationship.
– Point to the superclass.
39
Example
isa
fruit Juices
40