Professional Documents
Culture Documents
Relational Tables
Grant Weddell
David R. Cheriton School of Computer Science
University of Waterloo
CS 348
Introduction to Database Management
Spring 2012
ER to Relational
Fall 2011
1 / 16
Main ideas:
Each entity set maps to a new table
Each attribute maps to a new table column
Each relationship set maps to either new table columns or to a
new table
ER to Relational
Fall 2011
2 / 16
Entity of type E
row in table E
primary key of table
Primary key of entity set
Example:
Student
StudentNum
Major
StudentName
Student
StudentNum
CS 348 (Intro to DB Mgmt)
StudentName
ER to Relational
Major
Fall 2011
3 / 16
ER to Relational
Fall 2011
4 / 16
Account
AccNum
Log
Transaction
Date
TransNum
Amount
Account
AccNum
Balance
Transaction
TransNum
CS 348 (Intro to DB Mgmt)
AccNum
Date
ER to Relational
Amount
Fall 2011
5 / 16
table R
ER to Relational
Fall 2011
6 / 16
ER to Relational
Fall 2011
7 / 16
Address
Match
Location
HomeTeam
Team
Visitor
TeamName
Team
TeamName
LocName
Location
LocName
Address
Match
HomeTeamName
VisitorTeamName
LocName
Score
ER to Relational
Fall 2011
8 / 16
Representing Aggregation
ER to Relational
Fall 2011
9 / 16
CourseNum
Student
EnrolledIn
Course
StudentNum
CourseAccount
Account
Student
StudentNum
Course
CourseNum
ExpirationDate
UserId
Account
UserId
EnrolledIn
StudentNum
CourseNum
CourseAccount
UserId StudentNum CourseNum ExpirationDate
CS 348 (Intro to DB Mgmt)
ER to Relational
Fall 2011
10 / 16
Representing Specialization
Create table for higher-level entity set, and treat specialized entity
subsets like weak entity sets (without discriminators)
Example:
StudentNumber
Student
Student
StudentNumber StudentName
StudentName
Graduate
StudentNumber ProfessorName
Degree
Graduate
(1, 1)
SupervisedBy
(0, N)
Professor
StudentNumber Degree
Professor
Degrees
ProfessorName
ER to Relational
ProfessorName
Fall 2011
11 / 16
The higher-level entity set can be dened as a view on the tables for
the lower-level entity sets
ER to Relational
Fall 2011
12 / 16
MakeAndModel
LicenceNum
Vehicle
Price
COVERS
Tonnage
Truck
Car
AxelCount
MaxSpeed
PassengerCount
Truck
LicenceNum MakeAndModel
Price
Tonnage
Price
MaxSpeed
AxelCount
Car
LicenceNum MakeAndModel
CS 348 (Intro to DB Mgmt)
ER to Relational
PassengerCount
Fall 2011
13 / 16
Vehicle
LicenceNum
Vehicle
Price
LicenceNum
MakeAndModel
Price
COVERS
Truck
LicenceNum
Tonnage
Truck
Car
MaxSpeed
AxelCount
Car
LicenceNum
AxelCount
Tonnage
MaxSpeed
PassengerCount
PassengerCount
ER to Relational
Fall 2011
14 / 16
CourseNum
CourseName
(0, N)
SectionOf
Term
SectionNum
(1, 1)
Section
(1, 1)
(6, 50)
EnrolledIn
TaughtBy
Professor
OffSite
Section
ProfName
ProfNum
Student
Location
Mark
GPA
StudentName
StudentNum
ER to Relational
Fall 2011
15 / 16
Student
CourseNum
StudentNum
CourseName
StudentName
GPA
Section
EnrolledIn
CourseNum
SectionNum
StudentNum
Term
CourseNum
SectionNum
Term
ProfNum
Mark
OffSite Section
Professor
CourseNum
SectionNum
Term
ProfNum
ProfName
Location
CS 348 (Intro to DB Mgmt)
ER to Relational
Fall 2011
16 / 16