05 Mapping
05 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:
2
Step 1: Mapping of Regular Entity Types
3
Step 2: Mapping of Weak Entity Types
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.
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:
8
9
Already satisfied with step 2
10
11
Step 5: Mapping of Binary M:N Relationship Types
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.
13
Result of mapping of
previous steps
14
Correspondence between ER and Relational Models
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.
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