0% found this document useful (0 votes)
62 views32 pages

ER-to-Relational Mapping

The document describes the 7 steps to map an entity-relationship (ER) diagram to a relational database schema. Step 1 maps regular entity sets to relations, with the entity's key as the relation's primary key. Step 2 maps weak entities by including the owner's primary key as a foreign key. Step 3 maps 1:1 relationships either by including one entity's primary key in the other, merging the entities, or using a cross-reference relation. Step 4 maps 1:N relationships by including the 1's primary key as a foreign key in the N relation. Step 5 maps M:N relationships to a separate relation with the entities' primary keys as foreign keys. Step 6 maps multivalued attributes to

Uploaded by

bijaysubedi
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)
62 views32 pages

ER-to-Relational Mapping

The document describes the 7 steps to map an entity-relationship (ER) diagram to a relational database schema. Step 1 maps regular entity sets to relations, with the entity's key as the relation's primary key. Step 2 maps weak entities by including the owner's primary key as a foreign key. Step 3 maps 1:1 relationships either by including one entity's primary key in the other, merging the entities, or using a cross-reference relation. Step 4 maps 1:N relationships by including the 1's primary key as a foreign key in the N relation. Step 5 maps M:N relationships to a separate relation with the entities' primary keys as foreign keys. Step 6 maps multivalued attributes to

Uploaded by

bijaysubedi
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/ 32

ER-to-Relational Mapping

Step 1: Mapping of Regular Entity


Sets
• For each regular (strong) entity set 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
composite, the set of simple attributes that form
it will together form the primary key of R
Step 2: Mapping of Weak Entity
Sets
• For each weak entity set W in the ER schema
with owner entity set 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 set(s)
– 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 set W, if any
Step 3: Mapping of Binary 1:1
Relationship Sets
• For each binary 1:1 relationship set R in the ER
schema, identify the relations S and T that
correspond to the entity sets participating in R
(1) Foreign key approach: Choose one of the relations
(say S) with total participation and include the primary key
of T as a foreign key in S. Include all the simple attributes
(or simple components of composite attributes) of the 1:1
relationship set R as attributes of S
(2) Merged relation approach: When both participations
are total, merge the two entity sets and the relationship
into a single relation
(3) Cross-reference or relationship relation approach:
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 sets when none of the participation
is total
Step 4: Mapping of Binary 1:N
Relationship Sets
• For each binary 1:N relationship set R,
identify the relation S that represent the
participating entity set at the N-side of the
relationship set
– Include the primary key of the relation T that
represents the other entity set participating in
R as foreign key in S
– Include any simple attributes of the 1:N
relationship set as attributes of S
Step 5: Mapping of Binary M:N
Relationship Sets
• For each binary M:N relationship set R,
create a new relation S to represent R
– Include the primary keys of the relations that
represent the participating entity sets as foreign
key attributes in S; their combination will form
the primary key of S
– Also include any simple attributes of the M:N
relationship set (or simple components of
composite attributes) as attributes of S
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 set or relationship set that
has A as an attribute
– The primary key of R is the combination of A and K. If
the multivalued attribute is composite, include its simple
components
Step 7: Mapping of N-ary
Relationship Sets
• For each n-ary relationship set R, where
n>2, create a new relation S to represent R
– Include the primary keys of the relations that
represent the participating entity sets as foreign
key attributes in S. Foreign keys form the
primary key of S
– Also include any simple attributes of the n-ary
relationship set (or simple components of
composite attributes) as attributes of S
Example
Ternary relationship set: the SUPPLY relationship
Example (Cont.)
Mapping Aggregation
• Relationship will be mapped to a table; extended with
primary keys of participating entity set(s), plus its own
attributes (if exists)
• Example:

M N
Company Interview Job-Applicant

Results-In Job-Offer

RESULTS_IN P.K(Job_Offer) P.K(Company) P.K(Job-Applicant)


The ER Diagram for the
COMPANY Database
Mapping Result
Mapping the COMPANY ER diagram into a relational schema
ER to Relational Exercise

Loan#
M N
Customer Borrows Loan
Amount

SSN Name
Loanofficer Employee

Addr
ESSN Name
EER-to-Relational Mapping
Mapping of Specialization or
Generalization
• Convert each specialization with m subclasses
{S1, S2,….,Sm} and generalized superclass C,
where the attributes of C are {k,a1,…an} and k is
the primary key, into relational schemas using one
of the four following options:
– Option 1: Multiple relations-Superclass and
subclasses
• Create a relation L for C with attributes Attrs(L) = {k,a1,…an},
PK(L) = k
• Create a relation Li for each subclass Si, 1 < i < m, with the
attributes Attrs(Li) = {k} U {attributes of Si}, PK(Li)=k
• This option works for any specialization (total or partial,
disjoint or over-lapping)
Example
EER diagram notation for an attribute-defined
specialization on Job_type
Example (Cont.)
Mapping the EER diagram using option 1
Mapping of Specialization or
Generalization (Cont.)
• Option 2: Multiple relations-Subclass
relations only
– Create a relation Li for each subclass Si, 1 < i
< m, with the attributes Attrs(Li) = {attributes of
Si} U {k,a1…,an}, PK(Li) = k
– This option only works for a specialization
whose subclasses are total (every entity in
the superclass must belong to (at least) one
of the subclasses)
Example
Generalizing CAR and TRUCK into the superclass
VEHICLE
Example (Cont.)

Mapping the EER diagram using option 2


Mapping of Specialization or
Generalization (Cont.)
• Option 3: Single relation with one type attribute
– Create a single relation L with attributes Attrs(L) = {k,a1,…an} U
{attributes of S1} U…U {attributes of Sm} U {t}, PK(L) = k
– The attribute t is called a type (or discriminating) attribute that
indicates the subclass to which each tuple belongs, if any
– This option works only for a specialization whose subclasses are
disjoint
– This option has the potential for generating many null values if
many specific attributes exist in the subclasses
Example
EER diagram for an attribute-defined specialization on
Job_type
Example (Cont.)
Mapping the EER diagram using option 3
Mapping of Specialization or
Generalization (Cont.)
• Option 4: Single relation with multiple type
attributes
– Create a single relation L with attributes Attrs(L) =
{k,a1,…an} U {attributes of S1} U…U {attributes of Sm}
U {t1, t2,…,tm}, PK(L) = k
– Each ti, 1 < i < m, is a Boolean type attribute
indicating whether a tuple belongs to the subclass Si
– This option works for a specialization whose
subclasses are overlapping (but will also work for a
disjoint specialization)
Example
EER diagram for an overlapping specialization
Example (Cont.)
Mapping the EER diagram using option 4 with Boolean
type fields Mflag and Pflag
EER to Relational Summary
• Subclasses are overlapping ( will also work for
a disjoint specialization), each ti, 1 <=i<=m, is a
Boolean attribute indicating whether a tuple
belongs to subclass, Si
• Option 1 works on disjoint /overlapping and
total/partial
• Option 2 works well when both the disjoint and
total constraints hold
– For overlapping, some values will be stored multiple
times unnecessarily
Mapping of Shared Subclasses
• A shared subclass indicates multiple
inheritance
• Any of the options can be applied to a
shared subclass, subject to restrictions
Example
• A specialization lattice for a UNIVERSITY database
Example (Cont.)
• Option 3 is used in the EMPLOYEE relation
(Employee_type attribute)
• Option 4 is used in the STUDENT relation
(Stud_assist_flag attribute)
Exercise

You might also like