chapter 5 relational database design by er- and eer-to-relational mapping hour 1
DESCRIPTION
Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1. Presented & Modified by Mahmoud Rafeek Alfarra Lecturer in CST Kan younis. Chapter 5 Outline. Relational Database Design Using ER-to-Relational Mapping Mapping EER Model Constructs to Relations. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/1.jpg)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 5
Relational Database
Design by ER- and EER-to-Relational Mapping
Hour 1
Presented & Modified by
Mahmoud Rafeek AlfarraLecturer in CST Kan younis
![Page 2: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/2.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Chapter 5 Outline
Relational Database Design Using ER-to-Relational Mapping
Mapping EER Model Constructs to Relations
![Page 3: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/3.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Relational DatabaseDesign by ER- and EER-to-Relational Mapping
Design a relational database schema Based on a conceptual schema design
Seven-step algorithm to convert the basic ER model constructs into relations
Additional steps for EER model
![Page 4: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/4.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Relational Database Design Using ER-to-Relational Mapping
![Page 5: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/5.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
![Page 6: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/6.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
COMPANY database example Assume that the mapping will create tables
with simple single-valued attributes
Step 1: Mapping of Regular Entity Types For each regular entity type, create a relation R
that includes all the simple attributes of E Called entity relations
• Each tuple represents an entity instance
![Page 7: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/7.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 2: Mapping of Weak Entity Types For each weak entity type, create a relation R
and include all simple attributes of the entity type as attributes of R
Include primary key attribute of owner as foreign key attributes of R
![Page 8: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/8.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
ER-to-Relational Mapping Algorithm
![Page 9: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/9.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 3: Mapping of Binary 1:1 Relationship Types For each binary 1:1 relationship type
• Include primary key of one side as foreign key of the other side.
• Include other attributes of the relationship as attributes to the realtion.
![Page 10: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/10.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 4: Mapping of Binary 1:N Relationship Types For each regular binary 1:N relationship type
• Identify relation that represents participating entity type at N-side of relationship type
• Include primary key of other entity type as foreign key in S
• Include simple attributes of 1:N relationship type as attributes of S
![Page 11: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/11.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 5: Mapping of Binary M:N Relationship Types For each binary M:N relationship type
• Create a new relation S • Include primary key of participating entity types as
foreign key attributes in S • Include any simple attributes of M:N relationship
type
![Page 12: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/12.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 6: Mapping of Multivalued Attributes For each multivalued attribute
• Create a new relation• Primary key of R is the combination of A and K• If the multivalued attribute is composite, include its
simple components
![Page 13: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/13.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
ER-to-Relational Mapping Algorithm
Step 7: Mapping of N-ary Relationship Types For each n-ary relationship type R
• Create a new relation S to represent R• Include primary keys of participating entity types as
foreign keys• Include any simple attributes as attributes
![Page 14: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/14.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
و ذكـ�رو ذكـ�رقال تعالى:
) وا نــ, ى آم. ر. ل. ال(قــ, و( أ.ن6 أ.هــ( لــ. و.كـ.ات8 م ب.ر. ا ع.ل.ي(ه> نـ. ت.ح( ( ل.ف. وا ات6قـ. و.
ض> ر(اـأل. اء و. م. م�ن. الس6
:األعراف{.96}
![Page 15: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/15.jpg)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 5
Relational Database
Design by ER- and EER-to-Relational Mapping
Hour 2
Presented & Modified by
Mahmoud Rafeek AlfarraLecturer in CST Kan younis
![Page 16: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/16.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Discussion and Summary of Mapping for ER Model Constructs
![Page 17: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/17.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Discussion and Summary of Mapping for ER Model Constructs
In a relational schema relationship, types are not represented explicitly Represented by having two attributes A and B:
one a primary key and the other a foreign key
![Page 18: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/18.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping EER Model Constructs to Relations
Extending ER-to-relational mapping algorithm
![Page 19: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/19.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping of Specialization or Generalization
Step 8: Options for Mapping Specialization or Generalization (see pages 294-295) Option 8A: Multiple relations—superclass
and subclasses• For any specialization (total or partial, disjoint or
overlapping)
Option 8B: Multiple relations—subclass relations only
• Subclasses are total• Specialization has disjointedness constraint
![Page 20: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/20.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping of Specialization or Generalization
Option 8C: Single relation with one type attribute
• Type or discriminating attribute indicates subclass of tuple
• Subclasses are disjoint• Potential for generating many NULL values if many specific
attributes exist in the subclasses
Option 8D: Single relation with multiple type attributes
• Subclasses are overlapping • Will also work for a disjoint specialization
![Page 21: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/21.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping of Shared Subclasses (Multiple Inheritance)
Apply any of the options discussed in step 8 to a shared subclass
![Page 22: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/22.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping of Categories (Union Types)
Step 9: Mapping of Union Types (Categories) Defining superclasses have different keys Specify a new key attribute
• Surrogate key
![Page 23: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/23.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
![Page 24: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/24.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Summary
Map conceptual schema design in the ER model to a relational database schema Algorithm for ER-to-relational mapping Illustrated by examples from the COMPANY
database
Include additional steps in the algorithm for mapping constructs from EER model into relational model
![Page 25: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/25.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
و ذكـ�رو ذكـ�رال. رسـول اللـه صـلى اللـه عليـه وسلم: ق.
من صـلى العشـاء في جماعـة فكأنمـا قـام ـنـصـف ـاللـيـلـ ـومن صـلى الصـبح فـي جـماعـة فكـأنما صـلى الليـل كلهصحيح
![Page 26: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/26.jpg)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 5
Relational Database
Design by ER- and EER-to-Relational Mapping
External Practices
Hour 3Presented & Modified by
Mahmoud Rafeek AlfarraLecturer in CST Kan younis
![Page 27: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/27.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
(a) CUSTOMER entity type with simple attributes
Mapping a regular entity
(b) CUSTOMER relation
![Page 28: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/28.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
(a) CUSTOMER entity type with composite attribute
Mapping a composite attribute
(b) CUSTOMER relation with address detail
![Page 29: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/29.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping a multivalued attribute
1–to–many relationship between original entity and new relation
(a)
Multivalued attribute becomes a separate relation with foreign key
(b)
![Page 30: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/30.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
![Page 31: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/31.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity
Foreign key
Composite primary key
![Page 32: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/32.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Example of mapping a 1:M relationshipRelationship between customers and orders
Note the mandatory one
![Page 33: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/33.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping the relationship
Again, no null value in the foreign key…this is because of the mandatory minimum cardinality
Foreign key
![Page 34: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/34.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Example of mapping an M:N relationshipE-R diagram (M:N)
The Supplies relationship will need to become a separate relation
![Page 35: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/35.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Three resulting relations
New intersection
relationForeign key
Foreign key
Composite primary key
![Page 36: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/36.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping a binary 1:1 relationshipIn_charge relationship
![Page 37: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/37.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Resulting relations
![Page 38: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/38.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
![Page 39: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/39.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
![Page 40: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/40.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping an associative entity with an identifierAssociative entity
![Page 41: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/41.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Three resulting relations
![Page 42: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/42.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping a unary 1:N relationship
(a) EMPLOYEE entity with Manages relationship
(b) EMPLOYEE relation with recursive foreign key
![Page 43: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/43.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe modified by Mahmoud Rafeek Alfarra, April 2011
Mapping a unary M:N relationship
(a) Bill-of-materials relationships (M:N)
(b) ITEM and COMPONENT relations
![Page 44: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/44.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping a ternary relationshipTernary relationship with associative entity
![Page 45: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/45.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping the ternary relationship
Remember that the primary key MUST be
unique
![Page 46: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/46.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Figure 5-20: Supertype/subtype relationships
![Page 47: Chapter 5 Relational Database Design by ER- and EER-to-Relational Mapping Hour 1](https://reader036.vdocuments.site/reader036/viewer/2022081501/56813bb8550346895da4ea0a/html5/thumbnails/47.jpg)
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Mapping Supertype/subtype relationships to relations
These are implemented as one-to-one relationships