0% found this document useful (0 votes)
17 views

05 Mapping

Uploaded by

Sanjana Sanjana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

05 Mapping

Uploaded by

Sanjana Sanjana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

From ER to Relational Mapping

Now we focus on the logical database design or data model mapping step of
database design. Below the procedures to create a relational schema from an Entity-
Relationship (ER) schema.
1
Many computer aided software engineering (CASE) tools are based on the ER models, or other
similar models.
Many tools use ER diagrams to graphically develop the schema, and then convert it automatically
into a relational database schema by using a DDL language of a specific relational DBMS. This
conversion is provided with the implementation of algorithms.
Below six (steps) algorithms to convert the ER model and one (steps) algorithm for EER Model:

• Step ER 1: Mapping of Regular (strong) Entity Types,

• Step ER 2: Mapping of Weak Entity Types

• Step ER 3: Mapping of Binary 1:1 Relationship Types.

• Step ER 4: Mapping of Binary 1:N Relationship Types

• Step ER 5: Mapping of Binary M:N Relationship Types

• Step ER 6: Mapping of Multivalued Attributes

• Step EER 1: Mapping specialization and generalization

2
Step 1: Mapping of Regular Entity Types

• For each regular (strong) entity type E


in the ER, create a table R that includes
all the simple attributes of E.
• Include only the simple component
attributes of a composite attribute.
• Choose one of the key attributes of E as
the primary key for R. If the chosen key
of E is a composite, then the set of
simple attributes that form it, will
together form the primary key of R.

3
Step 2: Mapping of Weak Entity Types

• For each weak entity type W in the ER


with owner entity type E, create a table
R and include all simple attributes of W
as attributes of R.
• Include as foreign key attributes of R,
the primary key attribute(s) of the table
that correspond to the owner entity
type. The primary key of R is the
combination of the primary key(s) of
the owner and the partial key of the
weak entity type W, if any.

4
Step 3: Mapping of Binary 1:1 Relationship Types.
• For each binary 1:1 relationship type R
in the ER, identify the tables S and T
that correspond to the entity types
participating in R. There are three
possible approaches:
a) the foreign key approach (more useful)
b) the merged relationship approach
c) the cross reference or relationship
relation approach.
a) Foreign key approach:
• Choose one of the tables between S and T
and include in S as a foreign key the primary
key of T. It is better to choose an entity type
with total participation in R in the role of S.
• Include all the simple attributes (or simple
components of composite attributes) of the
1:1 relationship type R as attributes of S.

It is possible to include the primary key of S as a foreign key in T, but it


will have a NULL value for employee tuples who do not manage a
department. (Participations are not total) 5
b) Merged relation approach:
We can merge the two entity and the
relationship into a single relation.
This is possible when both
participations are total, because the
two tables will have the exact same
number of tuples.

Note: Solution (a) is the right solution because the participations are not total.
6
c) Cross-reference or relationship
relation approach:
Setting up a third table R for the
purpose of cross-referencing the
primary keys of the two tables S and T
representing the entity.
The table R will include the primary key
attributes of S and T as foreign keys to S
and T. The primary key of R will be one
of the two foreign keys,
The drawback is having an extra table,
and requiring an extra join operation
when combining related tuples from the
tables.

Manages

Note: Solution (a) is better because an extra relation, and an extra join operation is created.
7
Step 4: Mapping of Binary 1:N Relationship Types:

• For each binary 1:N relationship R,


identify the table S at the N-side of
the relationship. Include as foreign
key in S the primary key of the table
T that represents the other entity
participating in R; we do this because
each instance on the N-side can be
related to more than one instance on
the 1-side of the relationship.
• Include any simple attributes of the
relationship as attribute of S, if any.

8
9
Already satisfied with step 2

10
11
Step 5: Mapping of Binary M:N Relationship Types

• For each binary M:N relationship R,


create a new table S to represent R.
• Include as foreign key attributes in S,
the primary keys of the tables that
represent the participating entity; their
combination will form the primary key
of S.
• Include any simple attributes of the
M:N relationship as attributes of S, if
any.

Note: we cannot represent an M:N relationship by inserting a single foreign key attribute in one of the
participating tables; we must always create a separate new table.

12
Step 6: Mapping of Multivalued Attributes.

• For each multivalued attribute A create


a new table R.
• Include in R an attribute corresponding
to A
• Include in R the primary key attribute
(K) as a foreign key in R, where K is the
Pkey of the table that represents the
entity that has A as a multivalued
attribute.
• The primary key of R is the combination
of A and K.
• If the multivalued attribute is a
composite attribute, we include in R its
simple components.

13
Result of mapping of
previous steps

Result of mapping the COMPANY ER model into a


relational database model.
Foreign keys have been linked, with a directional line,
with their own Primary key.

14
Correspondence between ER and Relational Models

ER MODEL RELATIONAL MODEL

Entity Relation or Table


1:1 relationship Joining relation or Foreign Key (or relationship relation)
1:N relationship Foreign Key (or relationship relation)
M:N relationship Relationship relation and two foreign keys
Simple attribute Attribute
Composited Attribute Set of the simple component attributes
Multivalued attribute Table and foreign key
Value set Domain
Key attribute and/or Candidate key Primary key

15
Mapping EER Model Constructs to Relational model
(Only specialization and generalization)
There are several options for mapping a number of subclasses that together form a specialization (or
alternatively, that are generalized into a superclass).
Without enter in detail of all the possible options, we see only the option that is applicable to all possible
cases of specialization and generalization mapping.

This option is named Multiple relations—superclass and subclasses:


Generalization:
• Create a table for the Superclass, with the same attributes and same
Primary Key of Superclass and include the attributes of each related
subclasses. For example:

Specialization:
• Create a table for the Superclass, with the same attributes and same
Primary Key of Superclass.
• Create a table for each Subclass. Include in each one, the same
attributes of each relative subclass. Then in each table derived from
subclasses include, as foreign key, the primary key of the Superclass.
For example:

16

You might also like