01 01 EntityRelationship
01 01 EntityRelationship
Entity-Relationship Model
Lecture 1
Useful definitions
• A data model is a collection of concepts for describing data.
Relational Physical
Ideas ER design
schema database
Abstract Concrete
design design
Databases model the real world
• “Data Model” allows us to translate real world things into
structures computers can store
Attributes Title
Relationships Stars-in
Movies: Entity-Relationship diagram
Owns
Studios name
address
Relationships
Owns No arrow
now!
Studios
Studios
Example: Attributes on Relationships
Movies Stars
Contracts
length filmType
Studios
name addr
Example: Roles in a relationship
o An entity set can appear two or more times in a relationship.
o Each line to the entity set represents a different role.
Original
Sequel-of Movies
Sequel
o A movie may have many sequels, but for each sequel there is at most
one original movie.
Another design example.
“Bars-Beer-Drinkers” (BBD)
• Bars sell some beers.
• Drinkers like some beers.
• Drinkers frequent some bars.
Preferences
Drinkers
name addr
Example table for ternary (three-
way) relationships
Bar Drinker Beer
Joe’s Bar Ann Miller
Sue’s Bar Ann Bud
Sue’s Bar Ann Pete’s Ale
Joe’s Bar Bob Bud
Joe’s Bar Bob Miller
Joe’s Bar Cal Miller
Sue’s Bar Cal Bud Lite
Multiple relationships between two
entity sets
Favorite
“Exactly one” Multiplicity
Married
Husband Wife
Bob Ann
husband wife Joe Sue
Drinkers … …
Another role
Located-
at
Reached-by
Addresses Phones
Located-
at
teamName
Teams
wears rootsFor
memberOf captainOf
Players
name
Colors name Fans
prefers
Exercise 2 solution (Variant II)
teamName
Teams
wears
memberOf captainOf
name
Players
Colors favors
name
Fans
Exercise 2A. Teams and fans
database
• Modification A:
• Suppose we wish to add to the schema a relationship
“Led-by” among two players and a team. The intention
is that this relationship set consists of triples
(player1, player2, team)
such that player 1 played on the team at a time when
some
other player 2 was the team captain.
Draw the modification to the E/R diagram.
Exercise 2A solution
teamName
Teams
wears rootsFor
memberOf captainOf
leadBy period
Players
name