Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views16 pages

Chapter 9 Mapping

Chapter 7 discusses the process of mapping Entity-Relationship (ER) and Enhanced Entity-Relationship (EER) models to relational databases. It outlines a step-by-step algorithm for mapping various entity types, relationships, and attributes into relational schema, including regular entities, weak entities, and different types of relationships. The chapter provides examples to illustrate the mapping process for each type of entity and relationship.

Uploaded by

dearest.tinu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views16 pages

Chapter 9 Mapping

Chapter 7 discusses the process of mapping Entity-Relationship (ER) and Enhanced Entity-Relationship (EER) models to relational databases. It outlines a step-by-step algorithm for mapping various entity types, relationships, and attributes into relational schema, including regular entities, weak entities, and different types of relationships. The chapter provides examples to illustrate the mapping process for each type of entity and relationship.

Uploaded by

dearest.tinu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 7

Relational Database Design by


ER- and EER-to-Relational
Mapping

Copyright © 2004 Pearson Education, Inc.


5.5

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-2
5.6

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-3
Chapter Outline

⚫ER-to-Relational Mapping Algorithm


Step 1: Mapping of Regular Entity Types
Step 2: Mapping of Weak Entity Types
Step 3: Mapping of Binary 1:1 Relation Types
Step 4: Mapping of Binary 1:N Relationship Types.
Step 5: Mapping of Binary M:N Relationship Types.
Step 6: Mapping of Multivalued and composite attributes.
Step 7: Mapping of N-ary Relationship Types.

⚫Mapping EER Model Constructs to Relations


Step 8: Options for Mapping Specialization or Generalization.
Step 9: Mapping of Union Types (Categories).

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-4
FIGURE 7.1
The ER
conceptual
schema
diagram for
the
COMPANY
database.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-5
ER-to-Relational Mapping Steps
Step 1: Mapping of Regular Entity Types.

–For each regular (strong) entity type in the ER schema, create a


relation R that includes all the simple attributes of E.
–Choose one of the key attributes of E as the primary key for the
relation.

Example:
⚫We create the relations EMPLOYEE, DEPARTMENT, and PROJECT in the
relational schema corresponding to the regular entities in the ER diagram.
⚫SSN, DNUMBER, and PNUMBER are the primary keys for the relations
EMPLOYEE, DEPARTMENT, and PROJECT as shown.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-6
FIGURE 7.2
Result of
mapping the
COMPANY
ER schema
into a
relational
schema.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-7
ER-to-Relational Mapping Steps
Step 2: Mapping of Weak Entity Types

–For each weak entity type W in the ER schema with owner entity type E,
create a relation R and include all attributes of the weak entity as attributes of
the new relation R.
–Then, include the primary key of the owner entity as foreign key attributes of
R.
–The primary key of R is the combination of the primary key(s) of the owner(s)
and the partial key of the weak entity type W, if any.

Example:
⚫Create the relation DEPENDENT in this step to correspond to the weak entity type
DEPENDENT. Include the primary key SSN of the EMPLOYEE relation as a foreign key
attribute of DEPENDENT (renamed to ESSN).
⚫The primary key of the DEPENDENT relation is the combination {ESSN,
DEPENDENT_NAME} because DEPENDENT_NAME is the partial key of DEPENDENT.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-8
ER-to-Relational Mapping Steps
Step 3: Mapping of 1:1 Relation Types

For each 1:1 relationship type identify the entities participating in the
relationship. There are two possible approaches below:
(1) Foreign Key approach:
–Choose one of the relations and include a foreign key in one relation (S) which is the primary key of the
other relation (T). It is better to choose an entity type with total participation in the relationship in the role of
S.
–Example: 1:1 relation MANAGES is mapped by choosing the participating entity type DEPARTMENT to
serve in the role of S, because its participation in the MANAGES relationship type is total.

(2) Merged relation option:


–An alternate mapping of a 1:1 relationship type is possible by merging the two entity types and the
relationship into a single relation. This may be appropriate when both participations are total.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-9
ER-to-Relational Mapping Steps
Step 4: Mapping of Binary 1:N Relationship Types.

–For each regular 1:N relationship type R, identify the relation S, which
is the entity on the N-side of the relationship.
–Include as foreign key in S the primary key of the relation which is on
the 1 side of the relationship.
–Include any simple attributes of the 1:N relation type as attributes of S.

Example:
⚫1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION in the
figure. For WORKS_FOR we include the primary key DNUMBER of the
DEPARTMENT relation as foreign key in the EMPLOYEE relation and call it
DNO.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-10
ER-to-Relational Mapping Steps
Step 5: Mapping of Binary M:N Relationship Types.

–For each M:N relationship type, create a new relation S to represent the
relationship.
–Include as foreign key attributes in S the primary keys of the entities on each side
of the relationship; the combination of the two primary keys will form the primary
key of S.
–Also include any simple attributes of the M:N relationship type as attributes of S.

Example:
⚫The M:N relationship type WORKS_ON from the ER diagram is mapped by creating a
relation WORKS_ON in the relational database schema. The primary keys of the PROJECT
and EMPLOYEE relations are included as foreign keys in WORKS_ON and renamed PNO
and ESSN, respectively.
⚫Attribute HOURS in WORKS_ON represents the HOURS attribute of the relation type. The
primary key of the WORKS_ON relation is the combination of the foreign key attributes
{ESSN, PNO}.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-11
ER-to-Relational Mapping Steps
Step 6: Mapping of Multivalued attributes.

–For each multivalued attribute A, create a new relation. This relation will include
an attribute corresponding to the multi-valued attribute, plus the primary key
attribute of the relation that has the multi-valued attribute, K.
–The primary key attribute of the relation is the foreign key representing the
relationship between the entity and the multi-valued relation.
–The primary key of R is the combination of A and K.

Example:
⚫The relation DEPT_LOCATIONS is created. The attribute DLOCATION represents the
multivalued attribute LOCATIONS of DEPARTMENT, while DNUMBER-as foreign key-
represents the primary key of the DEPARTMENT relation. The primary key of R is the
combination of {DNUMBER, DLOCATION}.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-12
FIGURE 7.2
Result of
mapping the
COMPANY
ER schema
into a
relational
schema.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-13
ER-to-Relational Mapping
Step 7: Mapping of N-ary Relationship Types.
(Non-binary relationships)
–For each n-ary relationship type R, where n>2, create a new relation S
to represent the relationship.
–Include as foreign key attributes in S the primary keys of the relations
that represent the participating entities.
–Also include any simple attributes of the n-ary relationship type as
attributes of S.

Example:
⚫The relationship type SUPPY in the ER on the next slide. This can be mapped to the
relation SUPPLY shown in the relational schema, whose primary key is the combination of
the three foreign keys {SNAME, PARTNO, PROJNAME}

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-14
FIGURE 4.11
Ternary relationship types. (a) The SUPPLY relationship.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-15
FIGURE 7.3
Mapping the n-ary relationship type SUPPLY from
Figure 4.11a.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Chapter 7-16

You might also like