Professional Documents
Culture Documents
Design Choices
Mapping Steps
Design Choices
Conceptual
perspective
Users perspective
Module 5
ER to Relational Mapping
Storage perspective
INFS1200 / INFS7900
Information Systems
Model is the
basis for
several
commercial
DBMSs
The Entity
Relationship (ER)
Model is one of the
most widely used
methods for
conceptual design
Conceptual
Schema
(ER)
The Relational
CONCEPTUAL
DESIGN
Database
Requirements
LOGICAL
DESIGN
(MAPPING)
Logical
Schema
(Relational)
Internal
Schema
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Module 4 - Contents
Mapping Method
Ref:Text
Mapping Steps
Design Choices
Fname
Minit
Lname
Sex
Name
Chp. 7
Sec 7.1
Salary
Number
Address
Name
Locations
N
WORKS_FOR
Ssn
1. Entity Mapping
2. Weak Entity Mapping
3. Binary 1:1 Relationship Mapping
4. Binary 1: N Relationship Mapping
5. Binary M:N Relationship Mapping
6. Multi-valued Attribute Mapping
7. N-ary Relationship Mapping
EMPLOYEE
DEPARTMENT
Bdate
StartDate
NumberOfEmployees
1
MANAGES
supervisor
supervisee
CONTROLS
Hours
SUPERVISION
1
1
M
WORKS_ON
PROJECT
DEPENDENTS_OF
Example ER
Model: Company
Database
Name
N
Relationship
Location
Name
Sex
INFS1200/INFS7900 Information Systems
DEPENDENT
BirthDate
Number
Fname
Minit
Lname
Sex
Mapping Steps
Design Choices
Number
Name
Salary
Address
Name
Locations
WORKS_FOR
(1,1)
Ssn
employee
(4,N)
department
For each regular (non-weak) entity type E, create a relation R that includes
all simple attributes of E
EMPLOYEE
(1,1)
(0,1)
(0,1)
manager
DEPARTMENT
NumberOfEmployees
StartDate
Bdate
MANAGES
CONTROLS
supervisee
(0,N)
supervisor
Hours
(1,N)
SUPERVISION
worker
(0,N)
employee
(1,1)
WORKS_ON
controlledproject
(1,N)
project
Company
Database in
alternative
notation
(0,N)
controllingdepartment
departmentmanaged
PROJECT
DEPENDENTS_OF
Name
(1,1)
Relationship
Location
dependent
Name
Sex
Number
BirthDate
DEPENDENT
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Step 1: Example
Step 1: Example
Fname
Minit
Lname
Sex
Salary
Name
Address
EMPLOYEE [Ssn,
Fname, Mit, Lname,
Dob, Address, Sex,
Salary]
Name
Number
Locations
DEPARTMENT
[Dnumber, DName]
Ssn
EMPLOYEE
DEPARTMENT
Bdate
Mapping Steps
Design Choices
10
Mapping Steps
Design Choices
Step 1: Example
PROJECT
Name
Location
Number
11
12
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Step 2: Example
For each weak entity type W with owner entity type E create a relation R
that includes all simple attributes of W
EMPLOYEE
DEPENDENTS_OF
N
Relationship
Name
Sex
DEPENDENT
BirthDate
13
Mapping Steps
Design Choices
Mapping Steps
Design Choices
For each binary 1:1 relationship type RT, identify relations S & T that
correspond to the entity types participating in RT
Choose one relation (say S) and include as foreign key in S the primary key
of T
It is better to choose as S, the entity type with total participation in RT
Include all the simple attributes (or simple components of composite
attributes) of the 1:1 relationship type RT as attributes of S
15
Mapping Steps
Design Choices
Step 3: Example
StartDate
DEPARTMENT
16
Mapping Steps
Design Choices
14
DEPARTMENT
[Dnumber, DName,
MGRSSN, MgrStart]
1
MANAGES
DEPARTMENT serves in the role of S because its participation in the MANAGES relationship type is
total (every department has a manager)
Include the primary key of the EMPLOYEE relation as a foreign key in the DEPARTMENT relation
(renamed MGRSSN)
Include the simple attribute StartDate of the MANAGES relation (renamed MGRSTART)
17
18
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Step 4: Example
For each (non-weak) binary 1:N relationship type RT, identify relation S
that represents the participating entity type at the N-side of the
relationship type
Include as foreign key of S the primary key of relation T that represents the
other entity type participating in RT
Include any simple attributes (or simple components of composite attributes)
of the 1:N relationship type as attributes of S
N
WORKS_FOR
EMPLOYEE
19
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Step 4: Example
Step 4: Example
DEPARTMENT
CONTROLS
EMPLOYEE
20
supervisee
N
SUPERVISION
1
PROJECT
21
Mapping Steps
Design Choices
22
Mapping Steps
Design Choices
EMPLOYEE [Ssn, Fname, Mit, Lname, Dob, Address, Sex, Salary, Dno,
SuperSSN]
DEPARTMENT [Dnumber, Dname, MGRSSN,MgrStart]
PROJECT [Pno, PName, Plocation, DNum]
DEPENDENT [ESSN,DepName, Sex, DOB, Relationship]
23
24
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Step 5: Example
EMPLOYEE
WORKS_ON
EMPLOYEE [Ssn, Fname, Mit, Lname, Dob, Address, Sex, Salary, Dno,
SuperSSN]
DEPARTMENT [Dnumber, Dname, MGRSSN,MgrStart]
PROJECT [Pno, PName, Plocation, DNum]
DEPENDENT [ESSN,DepName, Sex, DOB, Relationship]
WORKS_ON [ESSN, PNo, Hours]
PROJECT
25
Mapping Steps
Design Choices
26
Mapping Steps
Design Choices
Note that 1:1 and 1:N relationships can be mapped in the same way as
M:N
Advantageous when few relationship instances exist (Sparse 1:1
Relationship) as it reduces the number of nulls that appear as foreign
key values
PK1 NK1
PK2 NK2
PK1 NK1
NULL
X
NULL
A
NULL
B
NULL
C
Standard Implementation
INFS1200/INFS7900 Information Systems
27
No Nulls as
Foreign Keys
Mapping Steps
Design Choices
M:N Implementation
Module 5: ER to Relational Mapping
28
Mapping Steps
Design Choices
Step 6: Example
Name
Number
Locations
DEPARTMENT
29
30
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Final Schema
For each n-ary relationship type RT, create a new relation S to represent
RT.
EMPLOYEE [Ssn, Fname, Mit, Lname, Dob, Address, Sex, Salary, Dno,
SuperSSN]
DEPARTMENT [Dnumber, Dname, MGRSSN,MgrStart]
PROJECT [Pno, PName, Plocation, DNum]
DEPENDENT [ESSN,DepName, Sex, DOB, Relationship]
WORKS_ON [ESSN, PNo, Hours]
DEPT_LOCS[DNumber, DLocation]
Include as foreign key attributes of S the primary keys of the relations that
represent the participating entity types in RT
Include any simple attributes of the n-ary relationship type
The combination of foreign keys referencing the relations representing the
participating entity types is used to form primary key of S
31
Mapping Steps
Design Choices
Mapping Steps
Design Choices
33
Ternary relationship
Ternary relationship with participation constraint of one entity type
having max=1
Weak entity with three owners
Semantically different representation of relationship between 3 entities
Mapping Steps
Design Choices
34
Quantity
Sname
Mapping Steps
Design Choices
Ternary relationship
SUPPLIER
32
ProjName
(1,N)
PartNo
SUPPLY
PROJECT
(1,N)
(1,N)
Quantity
Sname
SUPPLIER
PART
ProjName
(1,1)
PartNo
SUPPLY
PROJECT
(1,N)
(1,N)
PART
35
36
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Quantity
1
SUPPLIER
SS
SUPPLY
ProjName
Sname
ProjName
SUPPLIER
SPJ
SUPPLIES
PROJECT
PROJECT
M
Semantically
different from
ternary
relationship
M
PartNo
PartNo
CAN_SUPPLY
SP
USES
PART
Same as
ternary
relationship
PART
37
Ref:Text
Mapping Steps
Design Choices
38
Mapping Steps
Design Choices
Chp. 7
Sec 7.2.1
Step 8 (cont)
Option 8A
Option 8B
We create a relational table for each subclass. The attributes of the
superclass are merged into each of the subclasses.
The primary key of the subclass table is the primary key of the superclass.
We create a relational table for the superclass and create a relational table for
each subclass.
The primary key of each of the subclass is the primary key of the superclass.
Vehicle(Vid, Lic#)
Truck(Vid, Weight, #Axles)
Lic#
Vehicle
Weight
#Axles
#Seats
Vid
#Seats
Car
Truck
EngSize
Overlapping: redundancy
Partial: may lose superclass
entities not in any subclass
EngSize
39
40
Mapping Steps
Design Choices
Step 8 (cont)
Step 8 (cont)
Option 8C
Weight
Mapping Steps
Design Choices
Vehicle
#Axles
Car
Truck
Lic#
Vid
We create a single relational table for all subclasses and the superclass.
The attributes of the table is the union of all attributes plus the attribute T to indicate the
subclass to which each tuple belongs. T is NULL in tuples that do not belong to any
subclass (for partial constraints)
Option 8D
We create a single relational table for all subclasses and the superclass.
The attributes of the table is the union of all attributes plus m extra boolean
attributes for each subclass to indicate whether or not the tuple belongs to this
subclass.
Vtype
Dob
Vname
Vehicle
Truck
E#
Hours
Posn
d
Mload
Employee
Car
Overlapping
#Seats
41
Years
Admin
Part-Time
42
Mapping Steps
Design Choices
Mapping Steps
Design Choices
Expressibility of ER
Subjectivity of ER Design
43
Ref:Text
Mapping Steps
Design Choices
44
Mapping Steps
Design Choices
Chp. 3
Sec 3.7.3
name
sno
ctitle
enr-dept
Student
ccd
Studies
45
ctitle
ccd
Course
Studies
Student
offer
enrol
1
Department
Mapping Steps
Design Choices
name
sno
dname
ofr-dept
Course
Hod
dbudget
46
Mapping Steps
Design Choices
to
If a weak entity
participates in other
relationship types,
besides the identifying
relationship, then it has
to be modeled as a
weak entity
If the weak entity has only
one attribute, then it
may be modeled as a
multi-valued attribute of
the owner entity
dname
name
ssn
add
Employees
name
ssn
Employees
from
Dependents
Deps_of
add
dname
pos
Works-In3
to
INFS1200/INFS7900 Information Systems
47
48
Mapping Steps
Design Choices
Mapping Steps
Design Choices
name
ssn
dname
add
EPD
Project
dname
Works-In
cost
Department
dbudget
Department
projid
cost
Assigned-to
N
INFS1200/INFS7900 Information Systems
projid
add
Employees
dbudget
Project
Controlled
49
Ref:Text
Mapping Steps
Design Choices
50
Mapping Steps
Design Choices
Chp. 3
Ex 3.23
Example Exercise
Specifications
A bank, given by its code, name and head office address, can have several branches. Each
branch within a given bank has a branch number and address
One branch can have several accounts, each identified by an AC number. Every account has
a type, current balance, and one or more account holders
One branch can have several loans, each given by a unique loan number, type, amount and
one or more loan holders
The name, address, phones and id of all customers (account and loan) of the bank are
recorded and maintained
51
Mapping Steps
Design Choices
ER Diagram
BRANCHES
BANK-BRANCH
BANK
Name
BRANCHES
Addr
Code
52
Mapping Steps
Design Choices
ER Diagram
BANK
BANK-BRANCH
Addr
HO-Addr
Code
Branch-No
Name
HO-Addr
Branch-No
ACCTS
ACNo
Type
ACCOUNT
Balance
53
54
Mapping Steps
Design Choices
Mapping Steps
Design Choices
ER Diagram
BANK
ER Diagram
BRANCHES
BANK-BRANCH
BANK
BRANCHES
Addr
Code
Name
ACNo
Type
Addr
HO-Addr
LoanNo
ACCOUNT
Code
Branch-No
ACCTS
Type
HO-Addr
Name
Branch-No
ACCTS
LOANS
ACNo
LOAN
Type
LoanNo
ACCOUNT
LOANS
LOAN
Type
Amount
Balance
Mapping Steps
Design Choices
Addr
Phones
56
Mapping Steps
Design Choices
Relational Schema
Module 4 - Review
55
Name
CUSTOMER
AHOLDER
SSN
LHOLDER
Amount
Balance
BANK-BRANCH
57
Mapping Steps
Design Choices
58
Mapping Steps
Design Choices
Module 6
Elmasri & Navathe
Chapter 7
59
60