5/27/2018 Data Modeling Entity Relationship Diagrams
1/27Dale Roberts 1
Department of Computer and Information Science,
School of Science, IUPUI
Dale Roberts, Lecturer
Computer Science, IUPUI
E-mail: [email protected]
Data Modeling
Entity-Relationship Diagrams
5/27/2018 Data Modeling Entity Relationship Diagrams
2/27Dale Roberts 2
Framework for E-R
Design is a serious business.
The boss knows they want a database, butthey dont know what they want in it.
Sketching the key components is an efficient
way to develop a working database.
5/27/2018 Data Modeling Entity Relationship Diagrams
3/27Dale Roberts 3
Purpose of E-R Model
The E-R model allows us to sketch
database schema designs.Includes some constraints, but not operations.
Designs are pictures called ent i ty-
relat ionsh ip diagrams.Later: convert E-R designs to relational
DB designs.
5/27/2018 Data Modeling Entity Relationship Diagrams
4/27Dale Roberts 4
Entity Sets
Enti ty= thing or object.
Enti ty set= collection of similar entities.Similar to a class in object-oriented languages.
Att r ibute= property of (the entities of) an
entity set.Attributes are simple values, e.g. integers or character
strings, not structs, sets, etc.
5/27/2018 Data Modeling Entity Relationship Diagrams
5/27Dale Roberts 5
E-R Diagrams
In an entity-relationship diagram:
Entity set = rectangle.
Attribute = oval, with a line to the rectangle representing
its entity set.
Warning!
Graphical representations are inconsistent.
Attributes using ovals shall be changed to more of a
Class Diagram style later, to save space.
The later style insists on singular nouns and uses lines for
relationships.
5/27/2018 Data Modeling Entity Relationship Diagrams
6/27Dale Roberts 6
Example: Entity
Entity set Beershas two attributes, nameand
manf(manufacturer).
Each Beersentity has values for these twoattributes, e.g. (Bud, Anheuser-Busch)
Underlined attribute(s) is(are) primary key(s)
Beers
name manf
5/27/2018 Data Modeling Entity Relationship Diagrams
7/27Dale Roberts 7
Relationships
This relationship has an attribute associated
with it.
A relationshipconnects two or more entity sets.
It is represented by a diamond, with lines toeach of the entity sets involved.
5/27/2018 Data Modeling Entity Relationship Diagrams
8/27Dale Roberts 8
Example: Relationships
Drinkers addrname
Beers
manfname
Bars
name
license
addr
Note:license =
beer, full,none
Sells Bars sell somebeers.
Likes
Drinkers likesome beers.Frequents
Drinkers frequentsome bars.
5/27/2018 Data Modeling Entity Relationship Diagrams
9/27Dale Roberts 9
Relationship Set
The current value of an entity set is the set of
entities that belong to it.Example: the set of all bars in our database.
The value of a relationship is a relat ionship
set, a set of tuples with one component for each
related entity set.
5/27/2018 Data Modeling Entity Relationship Diagrams
10/27Dale Roberts 10
Example: Relationship Set
For the relationship Sells, we might have a
relationship set like:
Bar BeerJoes Bar BudJoes Bar MillerSues Bar BudSues Bar Petes AleSues Bar Bud Lite
5/27/2018 Data Modeling Entity Relationship Diagrams
11/27Dale Roberts 11
Multiway Relationships
Sometimes, we need a relationship that
connects more than two entity sets.Suppose that drinkers will only drink certain
beers at certain bars.
Our three binary relationships Likes, Sells, and Frequents
do not allow us to make this distinction.
But a 3-way relationship would.
5/27/2018 Data Modeling Entity Relationship Diagrams
12/27Dale Roberts
Example: 3-Way Relationship
3/31/2014 12
5/27/2018 Data Modeling Entity Relationship Diagrams
13/27Dale Roberts 13
Bars Beers
Drinkers
namename
addrmanf
name addr
license
Preferences
Example: 3-Way Relationship
5/27/2018 Data Modeling Entity Relationship Diagrams
14/27Dale Roberts 14
A Typical Relationship Set
Bar Drinker BeerJoes Bar Ann Miller
Sues Bar Ann BudSues Bar Ann Petes AleJoes Bar Bob BudJoes Bar Bob Miller
Joes Bar Cal MillerSues Bar Cal Bud Lite
5/27/2018 Data Modeling Entity Relationship Diagrams
15/27Dale Roberts 15
Many-Many Relationships
Focus: binaryrelationships, such as Sells
between Bars and Beers.In a many-many relationship, an entity of either
set can be connected to many entities of the
other set.
E.g., a bar sells many beers; a beer is sold by many bars.
5/27/2018 Data Modeling Entity Relationship Diagrams
16/27Dale Roberts 16
In Pictures:
many-many
5/27/2018 Data Modeling Entity Relationship Diagrams
17/27
Dale Roberts 17
Many-One Relationships
Some binary relationships are many-onefrom
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 beconnected to zero, one, or many entities of the
first set.
5/27/2018 Data Modeling Entity Relationship Diagrams
18/27
Dale Roberts 18
In Pictures:
many-one
5/27/2018 Data Modeling Entity Relationship Diagrams
19/27
Dale Roberts 19
Example: Many-One Relationship
Favorite, from Drinkersto Beersis many-one.
A drinker has at most one favorite beer.
But a beer can be the favorite of any number of
drinkers, including zero.
5/27/2018 Data Modeling Entity Relationship Diagrams
20/27
Dale Roberts 20
Example: Many-One Relationship
Drinkers BeersLikes
FavoriteNotice: two relationshipsconnect the same entitysets, but are different.
5/27/2018 Data Modeling Entity Relationship Diagrams
21/27
Dale Roberts 21
One-One Relationships
In a one-onerelationship, each entity of either
entity set is related to at most one entity of theother set.
Example: Relationship Best-sellerbetween
entity sets Manfs(manufacturer) and Beers.A beer cannot be made by more than one manufacturer,and no manufacturer can have more than one best-
seller (assume no ties).
5/27/2018 Data Modeling Entity Relationship Diagrams
22/27
Dale Roberts 22
In Pictures:
one-one
5/27/2018 Data Modeling Entity Relationship Diagrams
23/27
Dale Roberts 23
Representing Multiplicity
Show a many-one relationship by an arrow
entering the one side.Remember: Like a functional dependency.
Show a one-one relationship by arrows
entering both entity sets.
Rounded arrow= exactly one, i.e., each
entity of the first set is related to exactly
one entity of the target set.
Pointed arrow= zero or one, i.e., eachentity of the first set is related to zero or
one entity of the target set. (Optionality)
5/27/2018 Data Modeling Entity Relationship Diagrams
24/27
Dale Roberts 24
Example: One-One Relationship
Consider Best-sellerbetween Manfs and Beers.
Some beers are not the best-seller of anymanufacturer, so a rounded arrow to Manfs
would be inappropriate.
But a beer manufacturer has to have a best-seller.
5/27/2018 Data Modeling Entity Relationship Diagrams
25/27
Dale Roberts 25
In the E-R Diagram
Manfs BeersBest-seller
A manufacturer hasexactly one best
seller.
A beer is the best-seller for 0 or 1manufacturer.
5/27/2018 Data Modeling Entity Relationship Diagrams
26/27
Dale Roberts
Modeling Shift
26
5/27/2018 Data Modeling Entity Relationship Diagrams
27/27
Dale Roberts3/31/2014
Acknowledgements
McFadden and Hoffer. Database Management
Loney, Kevin. Oracle Database 10g The CompleteReference
Ullman, Jeff. Database Systems The Complete Book.
DatabaseAnswers.com