1. Lecture 3 - Entity Relationship Model
1
Fall 2001 Database Systems 1
Database Design Process
Real World
Requirements Analysis
Database
Requirements
Conceptual Design
Conceptual
Model
Logical Design
Physical Design
Logical
Schema
Functional
Requirements
Functional Analysis
Access
Specifications
Application Pgm Design
E-R Modeling
Choice of a
DBMS
Data Model
Mapping
Fall 2001 Database Systems 2
Entity-Relationship Model
• An entity is a collection of real-world objects that
have many common properties.
• Examples: Students, Instructors, Courses,
Sections
– Student entities have properties: name,
address, major, graduation-year
– A student may be “John Smith”, “22 Sage Rd.”,
“Computer Science”, “2000”
• An attribute is a data item that describes a property
of an entity
2. Lecture 3 - Entity Relationship Model
2
Fall 2001 Database Systems 3
Entities
Students
sid
student_name
mid_initialfirstnamelastname
hobbies
primary identifier
multi valued attribute
composite attribute
Fall 2001 Database Systems 4
Mapping Entities to Relations
• Each entity in an E-R model is mapped to a separate
relation
– the primary identifier is mapped to the primary key
(underlined!)
– all regular attributes are mapped to an attribute in the
table
– each subpart of a composite attribute is mapped to a
different attribute
– each multi-valued attributed is mapped to a separate
relation that inherits the primary key of the parent
relation
3. Lecture 3 - Entity Relationship Model
3
Fall 2001 Database Systems 5
Mapping Entities
Students
sid
student_name
mid_initialfirstnamelastname
hobbies
Students( sid, lastname,
firstname, mid_initial )
Hobbies( sid, hobby )
Foreign key sid references
the Students relation!
Fall 2001 Database Systems 6
Map the Auction Entities
Owners
oid
owner_name
mid_initialfirstnamelastname
email
phone
#itemsold
Buyers
buyid
buyer_name
email
phone
cc_num
address
street city
state zip
4. Lecture 3 - Entity Relationship Model
4
Fall 2001 Database Systems 7
Map the Auction Entities
Items
iid
name location
description
Bids
bid
amountdate/time
date time
Fall 2001 Database Systems 8
Relationships
• Given a set of entities E1,E2,…,Ek, a relationship R defines a
rule of correspondence between these entities.
– An instance r(e1,e2,…,ek) of the R relation means entities
e1,e2,…,ek are in a relation r at this instance.
– If two people are married, they are in a relationship:
married(Bob, Margaret)
– If a student A takes a course C offered by professor B,
then A,B,C are in a relationship.
5. Lecture 3 - Entity Relationship Model
5
Fall 2001 Database Systems 9
Relationships
Items
Buyers Bidsplace
own
Owners
accept
date
binary relationship
ternary relationship
Fall 2001 Database Systems 10
Cardinalities of Relationships
• Participation cardinalities of a relationship R for an
entity E are:
– min-card(E, R) : the minimum number of entities
in E that should be mapped via R
– max-card(E, R): the maximum number of
entities in E that can be mapped via R
• Own is a relation between owner and item
– Should each owner be selling items?
– How many items can an owner sell?
6. Lecture 3 - Entity Relationship Model
6
Fall 2001 Database Systems 11
Cardinalities of Relationships
E R F E R F E R F
One-to-one relationship
min-card(E, R)=0
max-card(E,R)=1
min-card(F,R)=0
max-card(F,R)=1
Many-to-one relationship
min-card(E, R)=0
max-card(E,R)=N
min-card(F,R)=1
max-card(F,R)=1
Many-to-many relationship
min-card(E, R)=0
max-card(E,R)=N
min-card(F,R)=0
max-card(F,R)=N
Fall 2001 Database Systems 12
Cardinalities
Items
Buyers Bidsplace
own
Owners
accept
date
(1,1) (0,N)
(0,N)
(0,1)
(0,N)
(1,1)(0,N)
7. Lecture 3 - Entity Relationship Model
7
Fall 2001 Database Systems 13
Cardinalities
• If max-card(E,R)=1 then E has single-valued participation in
R
• If max-card(E,R)=N then E has multi-valued participation in
R
• Given a binary relation R between E and F, R is said to be
– one-to-one if both E and F have single-valued
participation
– one-to-many if E has single and F has multi-valued
participation
– many-to-many if both E and F have multi-valued
participation
Fall 2001 Database Systems 14
Mapping Relationships to “Relations”
• Map one-to-one and one-to-many (or many-to-one)
relationships into the existing relations (derived from entities)
– If E-R-F is one-to-many, then include the primary key of the
relation for F in the relation for E.
– If E-R-F is one-to-one, then include key for E in F, or the
key for F in E.
– If E-R-F is many-to-many, create a new relation for R that
has the primary keys for both E and F.
– If R has attributes, migrate them to the relation with the
foreign keys!
Contains Foreign Key(s)
8. Lecture 3 - Entity Relationship Model
8
Fall 2001 Database Systems 15
Mapping the Auction Database
Owners( oid, itemsold, lastname, firstname,
mid_initial, phone )
OwnerEmail( oid, email )
Buyers( buyid, buyername, ccnum,street, state, city,
zip, phone )
BuyerEmail( buyid, email )
Items( iid, name, location, description, oid )
Bids( bid, date, time, amount, acceptingoid,
acceptdate, buyid, iid )
Fall 2001 Database Systems 16
Cardinalities
Items
Buyers Bidsplace
own
Owners
accept
date
(1,1) (0,N)
(0,N)
(0,1)
(0,N)
(1,1)(0,N)
9. Lecture 3 - Entity Relationship Model
9
Fall 2001 Database Systems 17
Problem
• Consider the design of a database to manage airline
reservations:
– For flights, it contains the departure and arrival
airports, dates and times
– For flights, it also contains a number of different
pricing plans with different conditions (Saturday
stay, advance booking, etc.)
– For passengers, it contains the name, telephone
number and seat type preference
– Reservations include the seat assigned to a
passenger
– Passengers can have multiple reservations
Fall 2001 Database Systems 18
Solution
airport flight
passenger
depart
arrive
date
date
time
time
reservation
seat
pricing plan
name
conditions
name phone seat pref
(0,N)
(0,N)
(0,N)
(0,N) (1,1)
(1,1)
11. Lecture 3 - Entity Relationship Model
11
Fall 2001 Database Systems 21
Entity Relationship Model
• Ternary relationships may be represented by binary
relationships
ItemsBuyers
Stores
buy_from
(0,N)
buy_item
sell_item
(0,N)
(0,N) (0,N)
(0,N)
(0,N) Is this conceptually
equivalent to the
previous ternary
relationship?
Fall 2001 Database Systems 22
Weak Entities
• The existence of a weak entity W depends on the existence
of another (strong) entity E through a relationship R.
• (Alternate) Two different weak entities may have the same
identity (key) if they are related to two different strong entities.
BranchBank has
(0,N) (1,1)
name
number address
12. Lecture 3 - Entity Relationship Model
12
Fall 2001 Database Systems 23
Weak Entities
• Weak entities can be mapped to the relational
model by:
– Map each weak entity E that depends on a strong
entity F to a new relation R
– Relation R contains all the attributes in E and the
primary key of F
– The primary key for R is the primary key of E and the
primary key of F
Fall 2001 Database Systems 24
Concerts
date
Classical
pieces
conductor
soloists
Other
performers
location
orchestra
Generalization Hierarchies
• Lower items inherit attributes of their parents
Option 1. Translate into
a single relation with a
flag for the “type” of entity
[many null values]
Option 2. Translate into
three entities and two
“is-a” relationships, then
translate the resulting graph.
13. Lecture 3 - Entity Relationship Model
13
Fall 2001 Database Systems 25
Extensions
• All relational DBMSs come with extensions that give more
flexibility to the DBA
• Examples from Informix
– composite attributes - translate as a record address of
type ROW(street string, city string, state string, zip
string)
– multi-valued attributes - translate into collection types
such as sets, lists, multi-sets (bags)
– hierarchies - create typed tables and translate into a
type hierarchy.
• REMEMBER, the extensions complicate the data model
and make certain SQL queries much harder or impossible,
leaving the database programmer with a much harder job
of maintaining the database!