SlideShare une entreprise Scribd logo
1  sur  13
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
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
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
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.
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?
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)
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)
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)
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)
Lecture 3 - Entity Relationship Model
10
Fall 2001 Database Systems 19
Entity Relationship Model
• Entities play different roles in a relationship
Employees supervises
Supervised-by
(1, 1)
Supervisor-of
(0, N)
Employees supervises
supervised
(0, N)
Projects
employee-supervisor
(1, 1)
project-supervisor
(1, N)
Recursive
relationship
eid
Employees(eid, …, supervisor-id)
Foreign key
to Employees
Fall 2001 Database Systems 20
Entity Relationship Model
• Many-to-many relationships are translated into new
“relations”
ItemsBuyers
Stores
buy
(0,N) (0,N)
(0,N)
 ¢¡¤£ ¥§¦©¨¢  ¢¨ ¦©§©¨  !§#¦
$% '(% ) % 0
$¢1 '(% )¤1 2
$0 '§2 ) % 3
$¢1 '3 )¤1 1
amount
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
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.
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!

Contenu connexe

Tendances

Entity relationship modelling - DE L300
Entity relationship modelling - DE L300Entity relationship modelling - DE L300
Entity relationship modelling - DE L300
Edwin Ayernor
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
eidah20
 

Tendances (20)

Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1
 
Ertorelnotes
ErtorelnotesErtorelnotes
Ertorelnotes
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMS
 
Chapter-9 Normalization
Chapter-9 NormalizationChapter-9 Normalization
Chapter-9 Normalization
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Entity relationship modelling - DE L300
Entity relationship modelling - DE L300Entity relationship modelling - DE L300
Entity relationship modelling - DE L300
 
Relational model
Relational modelRelational model
Relational model
 
Relational database design
Relational database designRelational database design
Relational database design
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management Systems
 
DataBase ch2
DataBase ch2DataBase ch2
DataBase ch2
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
The Relational Model
The Relational ModelThe Relational Model
The Relational Model
 
Dbms relational data model and sql queries
Dbms relational data model and sql queries Dbms relational data model and sql queries
Dbms relational data model and sql queries
 
Introduction to Relational Database Management Systems
Introduction to Relational Database Management SystemsIntroduction to Relational Database Management Systems
Introduction to Relational Database Management Systems
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
 
Chapter 3 Entity Relationship Model
Chapter 3 Entity Relationship ModelChapter 3 Entity Relationship Model
Chapter 3 Entity Relationship Model
 
Schema Integration, View Integration and Database Integration, ER Model & Dia...
Schema Integration, View Integration and Database Integration, ER Model & Dia...Schema Integration, View Integration and Database Integration, ER Model & Dia...
Schema Integration, View Integration and Database Integration, ER Model & Dia...
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
 
RDBMS_Unit 01
RDBMS_Unit 01RDBMS_Unit 01
RDBMS_Unit 01
 

Similaire à [Www.pkbulk.blogspot.com]dbms03

entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
IRWANBINISMAILKPMGur1
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
saurabhshertukde
 
Reasoning of database consistency through description logics
Reasoning of database consistency through description logicsReasoning of database consistency through description logics
Reasoning of database consistency through description logics
Ahmad karawash
 

Similaire à [Www.pkbulk.blogspot.com]dbms03 (20)

Database Management System
Database Management System Database Management System
Database Management System
 
Unit 2 DBMS
Unit 2 DBMSUnit 2 DBMS
Unit 2 DBMS
 
chapter 3-Data Modelling using Entity Relationship .pdf
chapter 3-Data Modelling using Entity Relationship .pdfchapter 3-Data Modelling using Entity Relationship .pdf
chapter 3-Data Modelling using Entity Relationship .pdf
 
database management system
database management systemdatabase management system
database management system
 
Ch 6
Ch 6Ch 6
Ch 6
 
entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
 
Dbms
DbmsDbms
Dbms
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Model
 
RDBMS ERD
RDBMS ERDRDBMS ERD
RDBMS ERD
 
ER MODEL.pptx
ER MODEL.pptxER MODEL.pptx
ER MODEL.pptx
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
DBMS - ER Model
DBMS - ER ModelDBMS - ER Model
DBMS - ER Model
 
Db lec 02_new
Db lec 02_newDb lec 02_new
Db lec 02_new
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02
 
Module 1 session 5
Module 1   session 5Module 1   session 5
Module 1 session 5
 
Module 2 - part i
Module   2 - part iModule   2 - part i
Module 2 - part i
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql concepts
 
Unit i b(er model)
Unit i b(er model)Unit i b(er model)
Unit i b(er model)
 
Revision ch 3
Revision ch 3Revision ch 3
Revision ch 3
 
Reasoning of database consistency through description logics
Reasoning of database consistency through description logicsReasoning of database consistency through description logics
Reasoning of database consistency through description logics
 

Plus de AnusAhmad

Plus de AnusAhmad (20)

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05
 
[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
8. java script
8. java script8. java script
8. java script
 
7. struts
7. struts7. struts
7. struts
 
5. servlets
5. servlets5. servlets
5. servlets
 
4. jsp
4. jsp4. jsp
4. jsp
 
3. applets
3. applets3. applets
3. applets
 
2. http, html
2. http, html2. http, html
2. http, html
 
1. intro
1. intro1. intro
1. intro
 
6. hibernate
6. hibernate6. hibernate
6. hibernate
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

[Www.pkbulk.blogspot.com]dbms03

  • 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)
  • 10. Lecture 3 - Entity Relationship Model 10 Fall 2001 Database Systems 19 Entity Relationship Model • Entities play different roles in a relationship Employees supervises Supervised-by (1, 1) Supervisor-of (0, N) Employees supervises supervised (0, N) Projects employee-supervisor (1, 1) project-supervisor (1, N) Recursive relationship eid Employees(eid, …, supervisor-id) Foreign key to Employees Fall 2001 Database Systems 20 Entity Relationship Model • Many-to-many relationships are translated into new “relations” ItemsBuyers Stores buy (0,N) (0,N) (0,N)  ¢¡¤£ ¥§¦©¨¢  ¢¨ ¦©§©¨ !§#¦ $% '(% ) % 0 $¢1 '(% )¤1 2 $0 '§2 ) % 3 $¢1 '3 )¤1 1 amount
  • 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!