0% found this document useful (0 votes)
13 views27 pages

03 Mapping

The document outlines the process of mapping Entity-Relationship Diagrams (ERD) to relational schemas, detailing how to represent strong and weak entity sets, multi-valued attributes, and various types of relationships (one-to-one, one-to-many, many-to-many, recursive, and n-ary). It also discusses approaches for mapping super/sub entity sets, including multi-relation and single-relation methods. Examples are provided to illustrate the mapping process and the creation of relational schemas.
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)
13 views27 pages

03 Mapping

The document outlines the process of mapping Entity-Relationship Diagrams (ERD) to relational schemas, detailing how to represent strong and weak entity sets, multi-valued attributes, and various types of relationships (one-to-one, one-to-many, many-to-many, recursive, and n-ary). It also discusses approaches for mapping super/sub entity sets, including multi-relation and single-relation methods. Examples are provided to illustrate the mapping process and the creation of relational schemas.
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/ 27

Mapping ERD to Relations

Chapter-9 of Navathe
Representation of Relations

• Student(idNo, name, cgpa, admissionYear)


OR
• Student
IdNO name cgpa admissionYear
Relational Representation of
Strong Entity Sets
• Create a relation Ri for each strong entity set Ei.
• Attributes of Ri: simple attributes and simple components
of composite attributes of entity set Ei
• Multi-valued attributes of entities are dealt with separately.
• The key of Ei will also be the primary key of Ri.
• The primary key can be referred to by other relations via
foreign keys in them to capture relationships as we see
later.
Relational Representation of
Weak Entity Sets
• Create R for weak entity E’
• Attributes of R will be
1. Attributes of the weak entity set E' and
2. Primary key attributes of the identifying owner entity E.
3. These attributes will also be a foreign key in R' referring to the relation
corresponding to E.

• Primary Key of R: partial key of E' + Key of E.


• 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.
Example

Mapping to relational schema:

Primary key of section: {sectionNo, courseId)


Relational Representation of
Multi-valued Attributes
• One relation R for each multi-valued attribute Mi.
• Attributes of R:
1. multi-valued attribute Mi
2. primary key attribute of entity / relationship set for which Mi is an attribute.

Primary Key of R: multi-valued attribute of R + Key of E.

ßemailId is multi-valued attribute.


Mapping One-to-One Binary
Relationships
• Let S and T be entity sets in relationship R and S', T' be
the relations corresponding to these entity sets.
• Choose an entity set which has total participation if there
is one (says, S)
• include the primary key of T' as a foreign key in S' referring to relation T’.
• include all simple attributes (and simple components of composite attributes) of
R as attributes of S’.
• If there is total participation on both sides, both entity
sets can be merged into one relation.
Example

• Bank gives at most one student loan to a student. All


student loans must be given to students only.

STUDENTLOAN
loanNo dateIssued Amount interest Institute StudentId

STUDENT
Institute Stdid Fathername
Mapping One-to-Many/Many-
to-One Binary Relationships
• Let S be the participating entity on the many-side and T
the other entity. Let S' and T' be the corresponding
relations.
• Include primary key of T' as foreign key in S‘.
• Include any simple attribute (and simple components of
composite attributes) of reltionship set as attributes of S‘.
Example
Mapping Many-to- Many
Binary Relationships
• Make a separate relation T for this relationship R
between entity sets E1 and E2.
• Let R1 and R2 be the relations corresponding to E1 and
E2 .
• Include primary key attributes of R1 and R2 as foreign
keys in T. Their combination is the primary key in T.
Example

Primary key of enrollment relation is {rollNo, courseId}


Mapping Recursive
Relationships
• Make a relation T for the participating entity set E ( this might
already be existing) and
• one relation for recursive relationship R.
• Attributes of R will be
1. It key has two attributes both takes the values from T. Both have similar but not
same.
2. Any other attribute of relationship
• Example:
Mapping n-ary Relationshps

• For each n-ary relationship type R, where n > 2, 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.
• Include simple attributes of R as attributes in S.
• The primary key of S is usually a combination of all the
foreign keys that reference the relations representing the
participating entity types.
• If cardinality of a participating entity is 1, then S should not include the foreign
key referencing that relation in the primary key of S.
Example

1 M

SUPPLY
Sname Part_no Proj_name quantity

• Primary key is {Part_no, Proj_name}


• Sname, Part_no, Proj_name are foreign keys to respective relations.
ER Model & Relational Model

• Entity type • Composite attribute


• Entity relation
• Set of simple component
• 1:1 or 1:N relationship attributes
type • Multivalued attribute
• Foreign key (or relationship relation)
• Relation and foreign key
• M:N relationship type
• Relationship relation and two foreign
• Value set
keys • Domain
• n-ary relationship type • Key attribute
• Relationship relation and n foreign
keys • Primary (or secondary) key

• Simple attribute
• Attribute

BITS Pilani, Pilani Campus


Mapping Super/Sub Entity
Sets
• Multi-relation approach
Approach 1:
• Make relation for super type and one for each subtype. Include PK of super type,
as FK in subtype relations.
• Create discriminator
• Works for all {total/partial specialization} and {disjoint/overlapping}

Approach2:
• Make no relation for super type. Make separate relations for all sub types.
Repeat super type attributes in each relation.
• Works only for total specialization and disjoint cases. For partial specialization,
some entities may be lost. For overlapping, attributes will be redundantly stored
in two or more relations.
Example
Example
Mapping Super/Sub Entity
Sets
Single-relation approach
• Good if subtypes have only few attributes.
Approach 1:
• Make a single relation and include all attributes of super type and subtype entity
sets.
• Include as many boolean attributes as there are subtypes.
• Works for disjoint and overlapping cases.
Approach2:
• Make a single relation and include all attributes of super type and subtype entity
sets.
• Include a single attribute called ‘discriminator’ whose value indicates to which
subtype that tuple belongs to.
• Works only for disjoint case. If there are many attributes in a subtype, they may
all be null.
Example

VEHICLE
Vehicle_ Pric License_plat CarFlg Max_sp No_of_p TruckFlg No_of_a
id e e_no eed assenger xles Tonnage
s
Example
Relational Schema
Acknowledgements

1. Pictures from Elmarsi R, & Navathe S B, Fundamental


of Database System, 5e, Pearson Education, 2008 are
used.

You might also like