Chapter 2 - C_ER_model
Chapter 2 - C_ER_model
Foreign Key
COMP3278 Introduction to
Database Management Systems
2
Example 1
3
Example 1
8
Example 2
To transform an ER model to
relational tables…
Step 1. Entity set -> table
Course (course code, name) Each entity set becomes a table.
Each attribute becomes a column.
Each entity is a tuple in the table.
9
Example 2
10
Example 2
11
Example 3
12
Example 3
Option 1
Customer (customerID, name)
Foreign key: none
VIP (customerID, discount_rate)
Foreign key: {customerID} referencing Customer
Member (customerID, accumulated_points)
Foreign key: {customerID} referencing Customer
13
Example 3
Option 1
Customer (customerID, name)
Foreign key: none
VIP (customerID, discount_rate)
Foreign key: {customerID} referencing Customer
Member (customerID, accumulated_points)
Foreign key: {customerID} referencing Customer
Option 2
Customer (customerID, name)
Foreign key: none
Handling ISA relationship VIP (customerID, name, discount_rate)
Option 2 : Foreign key: {customerID} referencing Customer
Member (customerID, name, accumulated_points)
Form a table for each entity
Foreign key: {customerID} referencing Customer
set with all local and inherited
attributes 14
Example 3
Option 1
[Storage] Option 1 has less Customer (customerID, name)
storage redundancy. Foreign key: none
[Efficiency] Accessing data (e.g, VIP (customerID, discount_rate)
retrieving the name and Foreign key: {customerID} referencing Customer
discount_rate of a VIP) in option Member (customerID, accumulated_points)
1 requires accessing two tables Foreign key: {customerID} referencing Customer
(not as efficient as option 2,
which requires accessing one
table only)! Option 2
Customer (customerID, name)
Foreign key: none
VIP (customerID, name, discount_rate)
Foreign key: {customerID} referencing Customer
What are the advantage
Member (customerID, name, accumulated_points)
and disadvantage of these
Foreign key: {customerID} referencing Customer
options?
15
Example 3
Option 1
Customer (customerID, name)
Foreign key: none
Total VIP (customerID, discount_rate)
specialization Foreign key: {customerID} referencing Customer
Member (customerID, accumulated_points)
Foreign key: {customerID} referencing Customer
Option 2
Customer (customerID, name)
Foreign key: none
Option 3 VIP (customerID, name, discount_rate)
VIP (customerID, name, discount rate) Foreign key: {customerID} referencing Customer
Foreign key: none Member (customerID, name, accumulated_points)
Member (customerID, name, Foreign key: {customerID} referencing Customer
accumulated points)
Foreign key: none
16
Example 4
Handling Multivalue
attributes
Multivalue attribute
becomes a table.
Customer (customerID, name)
Foreign key: none
17
Chapter 2C
END
COMP3278 Introduction to
Database Management Systems