CS3200 – Database Design···Spring 2018···Derbinsky
ER-to-Relational
Mapping
1
CS3200 – Database Design···Spring 2018···Derbinsky
Resulting Relational Schema
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
4
CS3200 – Database Design···Spring 2018···Derbinsky
Example ERD
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
5
CS3200 – Database Design···Spring 2018···Derbinsky
Step 1 Result
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
6
CS3200 – Database Design···Spring 2018···Derbinsky
Step 2: Weak Entity Types
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
7
i. For each weak entity type, create a
corresponding relation that includes all the
simple attributes
ii. Add as a foreign key all of the primary key
attribute(s) in the entity corresponding to
the owner entity type
CS3200 – Database Design···Spring 2018···DerbinskyExample
ERD
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
8
CS3200 – Database Design···Spring 2018···Derbinsky
Step 2 Result
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
9
CS3200 – Database Design···Spring 2018···DerbinskyStep 3: Mapping Binary 1 -to-1
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
10
Foreign Key
i. Choose one relation as S, the other T
 Better if S has total participation (reduces
number of NULL values)
ii. Add to S all the simple attributes of the
relationship
iii. Add as a foreign key in S the primary key
attributes of T
CS3200 – Database Design···Spring 2018···DerbinskyExample ERD
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
11
CS3200 – Database Design···Spring 2018···Derbinsky
Step 3 Result
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
12
CS3200 – Database Design···Spring 2018···DerbinskyStep 4: Binary 1-
to-N
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
13
i. Choose the S relation as the type at the
N-side of the relationship, other is T
ii. Add as a foreign key to S all of the
primary key attribute(s) of T
Another approach: create a relationship
relation
CS3200 – Database Design···Spring 2018···DerbinskyExample
ERD
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
14
CS3200 – Database Design···Spring 2018···Derbinsky
Step 4 Result
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
15
CS3200 – Database Design···Spring 2018···DerbinskyStep 5: Multivalued
Attributes
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
16
i. Create a new relation S
ii. Add as foreign keys the primary keys of
the corresponding relation
iii. Add the attribute to S (if composite, the
simple attributes); the combination of all
attributes in S forms the primary key
CS3200 – Database Design···Spring 2018···DerbinskyExample
ERD
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
17
CS3200 – Database Design···Spring 2018···Derbinsky
Step 6 Result
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
18
CS3200 – Database Design···Spring 2018···Derbinsky
Step 7: Specialization/Generalization
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
19
A. Multiple relations – subclass and superclass
 Usually works (assumes unique id at parent)
B. Multiple relations – subclass only
 Should only be used for disjoint
C. Single relation with one type attribute
 Only for disjoint, can result in many NULLs
D. Single relation with multiple type attributes
 Better for overlapping, could be disjoint
CS3200 – Database Design···Spring 2018···DerbinskySpecialization/Generalization
(A)
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
20
CS3200 – Database Design···Spring 2018···DerbinskySpecialization/Generalization
(B)
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
21
CS3200 – Database Design···Spring 2018···DerbinskySpecialization/Generalization
(C)
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
22
CS3200 – Database Design···Spring 2018···DerbinskySpecialization/Generalization
(D)
ER-TO-RELATIONAL MAPPING
MARCH 1, 2018
23

Lecture 08 mapping-converted

  • 1.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky ER-to-Relational Mapping 1
  • 4.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Resulting Relational Schema ER-TO-RELATIONAL MAPPING MARCH 1, 2018 4
  • 5.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Example ERD ER-TO-RELATIONAL MAPPING MARCH 1, 2018 5
  • 6.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 1 Result ER-TO-RELATIONAL MAPPING MARCH 1, 2018 6
  • 7.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 2: Weak Entity Types ER-TO-RELATIONAL MAPPING MARCH 1, 2018 7 i. For each weak entity type, create a corresponding relation that includes all the simple attributes ii. Add as a foreign key all of the primary key attribute(s) in the entity corresponding to the owner entity type
  • 8.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyExample ERD ER-TO-RELATIONAL MAPPING MARCH 1, 2018 8
  • 9.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 2 Result ER-TO-RELATIONAL MAPPING MARCH 1, 2018 9
  • 10.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyStep 3: Mapping Binary 1 -to-1 ER-TO-RELATIONAL MAPPING MARCH 1, 2018 10 Foreign Key i. Choose one relation as S, the other T  Better if S has total participation (reduces number of NULL values) ii. Add to S all the simple attributes of the relationship iii. Add as a foreign key in S the primary key attributes of T
  • 11.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyExample ERD ER-TO-RELATIONAL MAPPING MARCH 1, 2018 11
  • 12.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 3 Result ER-TO-RELATIONAL MAPPING MARCH 1, 2018 12
  • 13.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyStep 4: Binary 1- to-N ER-TO-RELATIONAL MAPPING MARCH 1, 2018 13 i. Choose the S relation as the type at the N-side of the relationship, other is T ii. Add as a foreign key to S all of the primary key attribute(s) of T Another approach: create a relationship relation
  • 14.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyExample ERD ER-TO-RELATIONAL MAPPING MARCH 1, 2018 14
  • 15.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 4 Result ER-TO-RELATIONAL MAPPING MARCH 1, 2018 15
  • 16.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyStep 5: Multivalued Attributes ER-TO-RELATIONAL MAPPING MARCH 1, 2018 16 i. Create a new relation S ii. Add as foreign keys the primary keys of the corresponding relation iii. Add the attribute to S (if composite, the simple attributes); the combination of all attributes in S forms the primary key
  • 17.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskyExample ERD ER-TO-RELATIONAL MAPPING MARCH 1, 2018 17
  • 18.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 6 Result ER-TO-RELATIONAL MAPPING MARCH 1, 2018 18
  • 19.
    CS3200 – DatabaseDesign···Spring 2018···Derbinsky Step 7: Specialization/Generalization ER-TO-RELATIONAL MAPPING MARCH 1, 2018 19 A. Multiple relations – subclass and superclass  Usually works (assumes unique id at parent) B. Multiple relations – subclass only  Should only be used for disjoint C. Single relation with one type attribute  Only for disjoint, can result in many NULLs D. Single relation with multiple type attributes  Better for overlapping, could be disjoint
  • 20.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskySpecialization/Generalization (A) ER-TO-RELATIONAL MAPPING MARCH 1, 2018 20
  • 21.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskySpecialization/Generalization (B) ER-TO-RELATIONAL MAPPING MARCH 1, 2018 21
  • 22.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskySpecialization/Generalization (C) ER-TO-RELATIONAL MAPPING MARCH 1, 2018 22
  • 23.
    CS3200 – DatabaseDesign···Spring 2018···DerbinskySpecialization/Generalization (D) ER-TO-RELATIONAL MAPPING MARCH 1, 2018 23