Sei sulla pagina 1di 4

Chapter 6

ER-to-Relational Mapping

Translating an ER diagram into a relational schema is a largely mechanical


process. The primary work of designing a relational database is in developing
the conceptual schema (the ER diagram) rather than the logical schema.

6.1 Mapping Entity Types


Step 1 — Map regular entity types.
For each regular entity type E, create a new relation R which has
all of the simple attributes (and simple components of composite
attributes) of E. The key attributes of E become the primary key
for R.

Step 2 — Map weak entity types.


For each weak entity type W with owner entity type E, create a
relation R whose attributes are the simple attributes (and simple
components of composite attributes) of W plus the primary key of
E (as a foreign key). The primary key for R consists of the key
attributes of E along with the partial key attributes of W .

6.2 Mapping Binary Relationship Types


For binary relationship types, there are three approaches. Let S and T be the
relations corresponding to the two entity types involved in the relationship type.

Foreign key approach. Add the simple attributes (and simple components
of composite attributes) belonging to the relationship type to one of the
relations (such as S), along with the primary key of the other relation (as
a foreign key).

20
6.3. MAPPING MULTIVALUED
CHAPTER
ATTRIBUTES
6. ER-TO-RELATIONAL MAPPING

Merged relation approach. Combine S and T into a single relation with the
attributes of S and T plus the simple attributes (and simple components
of composite attributes) belonging to the relationship type. The primary
key of the merged relation is the combination of the primary keys of S
and T .

Cross-reference approach. Create a new relation R with the simple attributes


(and simple components of composite attributes) belonging to the relation-
ship type plus the primary keys of S and T as foreign keys. The primary
key of R is the combination of the primary keys of S and T .

Step 3 — Map binary 1:1 relationship types.


If both entity types have total participation in the relationship, the
merged relation approach can be used.
If only one entity type has total participation, the foreign key ap-
proach can be used with S being the relation corresponding to the
total-participation entity. If neither entity type has total participa-
tion, either the foreign key approach or the cross-reference approach
can be used. The cross-reference approach is advantageous if few
entities of S participate in the relationship because it avoids lots of
NULL values.
Step 4 — Map binary 1:N relationship types.
Use either the foreign key approach where S is the relation corre-
sponding to the entity type on the N side of the relationship or the
cross-reference approach. The latter is advantageous if few entities
of S participate in the relationship because it avoids lots of NULL
values.
Step 5 — Map binary M:N relationship types.
The cross-reference approach must be used.

6.3 Mapping Multivalued Attributes


Step 6 — Map multivalued attributes.
Create a new relation R for each multivalued attribute A. The at-
tributes of R consist of A (this may be the components of A if A is a
composite attribute) and the primary key of the relation correspond-
ing to the entity type E that A belongs to (as a foreign key). All of
R’s attributes belong to its primary key.

6.4 Mapping n-ary Relationship Types


Step 7 — Map n-ary relationship types.

August 27, 2018 21


6.5. MAPPING SPECIALIZATION
CHAPTER 6. ER-TO-RELATIONAL MAPPING

For ternary and higher degree relationship types, use an extension


of the cross-reference approach - create a new relation R with the
simple attributes (and simple components of composite attributes)
of the relationship type plus the primary keys of all of the relations
whose corresponding entity types participate in the relationship. The
primary key of R is the combination of the primary keys from the
other relations.

6.5 Mapping Specialization


There are four main options for mapping specializations.

Multiple relations — superclass and subclasses. Create one relation for


the superclass and each subclass. The superclass relation has the at-
tributes of the superclass, while each subclass relation has the attributes
of the subclass plus the primary key of the superclass relation (as a foreign
key). The primary key of the superclass relation consists of the key at-
tribute(s) of the superclass, while the primary key of each subclass relation
is the superclass key.
Multiple relations — subclasses. Create one relation for each subclass. Each
subclass relation has the attributes of the subclass plus the attributes and
primary key of the superclass relation (as a foreign key). The primary key
of each subclass relation is the superclass key.
Single relation — one type attribute. Create a single relation with all of
the attributes of the superclass and all subclasses plus a type attribute
which identifies which subclass an entity belongs to. The primary key is
the superclass key.
Single relation — multiple type attributes. Create a single relation with
all of the attributes of the superclass and all subclasses plus a boolean
type attribute for each subclass. The primary key is the superclass key.

Step 8 — Map specializations.


Any specialization can be mapped into separate relations for the su-
perclass and each subclass. The subclass-only version can be used for
total specializations. In both cases, an entity may be duplicated in
separate relations if the subclasses are overlapping.
Of the single-relation approaches, a single type attribute can be used
when the specialization is disjoint. The multiple type attribute ap-
proach works for both overlapping and disjoint specializations.

6.6 Mapping Category Types


Step 9 — Map category types.

August 27, 2018 22


6.6. MAPPING CATEGORY
CHAPTER
TYPES 6. ER-TO-RELATIONAL MAPPING

Create a relation for the category with the simple (and simple com-
ponents of composite attributes) attributes of the category type plus
either the primary key of the superclasses as a foreign key (if the
superclasses have a common key) or a new surrogate key (if the su-
perclasses do not have a common key). The surrogate key is also
added as an attribute to the relations corresponding to the relations
for the superclasses. The primary key of the category relation is the
superclass key or the surrogate key.

August 27, 2018 23

Potrebbero piacerti anche