Er Mapping
Er Mapping
Er Mapping
●
FUNDAMENTALS OF Database Systems SEVENTH EDITION. Ramez Elmasri, Shamkant B. Navathe
●
Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping
●
Pg 290
1
2
3
4
Step 1: Mapping of Regular Entity Types.
●
For each regular (strong) entity type E in the ER schema, create a relation 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.
5
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 simple attributes (or simple components of composite attributes) of W as attributes of R.
●
In addition, include as foreign key attributes of R, the primary key attribute(s) of the relation(s) that
correspond to the owner entity type(s); this takes care of mapping the identifying relationship type of
W.
●
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.
●
If there is a weak entity type E2 whose owner is also a weak entity type E1, then E1 should be mapped
before E2 to determine its primary key first.
6
7
Step 3: Mapping of Binary 1:1 Relationship
Types.
●
For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that correspond
to the entity types participating in R.
●
There are three possible approaches:
●
(1) the foreign key approach,
●
(2) the merged relationship approach, and
●
(3) the crossreference or relationship relation approach.
8
1.Foreign Key approach
●
This approach is the most useful and should be followed unless special conditions exist.
●
Choose one of the relations—S, say—and include as a foreign key in S 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.
9
2. Merged relation approach
●
An alternative mapping of a 1:1 relationship type is to merge the two entity types and the relationship
into a single relation.
●
This is possible when both participations are total, as this would indicate that the two tables will have
the exact same number of tuples at all times.
10
3. Cross-reference or relationship relation
approach
●
The third option is to set up a third relation R for the purpose of cross-referencing the primary keys of
the two relations S and T representing the entity types.
●
This approach is required for binary M:N relationships.
●
The relation R is called a relationship relation (or sometimes a lookup table), because each tuple in R
represents a relationship instance that relates one tuple from S with one tuple from T.
●
The relation 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, and the other foreign key will be a unique key
of R.
●
The drawback is having an extra relation, and requiring extra join operations when combining related
tuples from the tables
11
Step 4: Mapping of Binary 1:N Relationship
Types.
●
There are two possible approaches:
●
(1) the foreign key approach and
●
(2) the cross-reference or relationship relation approach.
●
The first approach is generally preferred as it reduces the number of tables
12
1. The foreign key approach
●
For each regular binary 1:N relationship type R, identify the relation S that represents the participating
entity type at the N-side of the relationship type.
●
Include as foreign key in S the primary key of the relation T that represents the other entity type
participating in R; we do this because each entity instance on the N-side is related to at most one entity
instance on the 1-side of the relationship type.
●
Include any simple attributes (or simple components of composite attributes) of the 1:N relationship
type as attributes of S.
13
14
2. The relationship relation approach.
●
An alternative approach is to use the relationship relation (cross-reference) option as in the third
option for binary 1:1 relationships.
●
We create a separate relation R whose attributes are the primary keys of S and T, which will also be
foreign keys to S and T.
●
The primary key of R is the same as the primary key of S.
●
This option can be used if few tuples in S participate in the relationship to avoid excessive NULL values
in the foreign key
15
Step 5: Mapping of Binary M:N Relationship
Types.
●
In the traditional relational model with no multivalued attributes, the only option for M:N relationships
is the relationship relation (cross-reference) option.
●
For each binary M:N relationship type R, create a new relation S to represent R.
●
Include as foreign key attributes in S the primary keys of the relations that represent the participating
entity types; their combination will form the primary key of S.
●
Also include any simple attributes of the M:N relationship type (or simple components of composite
attributes) as attributes of S.
●
Notice that we cannot represent an M:N relationship type by a single foreign key attribute in one of the
participating relations (as we did for
16
17
Step 6: Mapping of Multivalued Attributes.
●
For each multivalued attribute A, create a new relation R.
●
This relation R will include an attribute corresponding to A, plus the primary key attribute K—as a
foreign key in R—of the relation that represents the entity type or relationship type that has A as a
multivalued attribute.
●
The primary key of R is the combination of A and K. If the multivalued attribute is composite, we
include its simple components
18
19