ER→Relational Mapping

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [0/17]
❖ ER to Relational Mapping

Reminder: a useful strategy for database design:

A formal mapping exists for ER model Relational model.

This maps "structures"; but additional info is needed, e.g.

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [1/17]
❖ Relational Model vs ER Model

Correspondences between relational and ER data models:

Differences between relational and ER models:
Note that ...
COMP3311 20T3 ♢ ER→Rel Mapping ♢ [2/17]
❖ Mapping Strong Entities

An entity set E with atomic attributes a1, a2, ... an

maps to

A relation R with attributes (columns) a1, a2, ... an

Example:

[Diagram:Pics/er-rel/strongent.png]


Note: the key is preserved in the mapping.

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [3/17]
❖ Mapping Weak Entities

Example:

[Diagram:Pics/er-rel/mapwkent.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [4/17]
❖ Mapping N:M Relationships

Example:

[Diagram:Pics/er-rel/mapnnrel.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [5/17]
❖ Mapping 1:N Relationships

Example:

[Diagram:Pics/er-rel/map1nrel2.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [6/17]
❖ Mapping 1:1 Relationships

Example:

[Diagram:Pics/er-rel/map11rel.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [7/17]
❖ Mapping 1:1 Relationships (cont)

If there is no reason to favour one side of the relationship ...

[Diagram:Pics/er-rel/map11rel3.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [8/17]
❖ Mapping n-way Relationships

Relationship mappings above assume binary relationship.

If multiple entities are involved:

Some people advocate converting n-way relationships into:
COMP3311 20T3 ♢ ER→Rel Mapping ♢ [9/17]
❖ Mapping Composite Attributes

Composite attributes are mapped by concatenation or flattening.

Example:

[Diagram:Pics/er-rel/mapstrent.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [10/17]
❖ Mapping Multi-valued Attributes (MVAs)

MVAs are mapped by a new table linking values to their entity.

Example:

[Diagram:Pics/er-rel/mapmva.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [11/17]
❖ Mapping Multi-valued Attributes (MVAs) (cont)

Analogy:

[Diagram:Pics/er-rel/mapmva1.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [12/17]
❖ Mapping Multi-valued Attributes (MVAs) (cont)

Example: the two entities


Person(12345, John, 12-feb-1990, [red,green,blue])
Person(54321, Jane, 25-dec-1990, [green,purple])

would be represented as

Person(12345, John, 12-feb-1990)
Person(54321, Jane, 25-dec-1990)
FavColour(12345, red)
FavColour(12345, green)
FavColour(12345, blue)
FavColour(54321, green)
FavColour(54321, purple)

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [13/17]
❖ Mapping Subclasses

Three different approaches to mapping subclasses to tables:

Which mapping is best depends on how data is to be used.
COMP3311 20T3 ♢ ER→Rel Mapping ♢ [14/17]
❖ Mapping Subclasses (cont)

Example of ER-style mapping:

[Diagram:Pics/er-rel/mapsubclass.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [15/17]
❖ Mapping Subclasses (cont)

Example of object-oriented mapping:

[Diagram:Pics/er-rel/mapsubclass2.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [16/17]
❖ Mapping Subclasses (cont)

Example of single-table-with-nulls mapping:

[Diagram:Pics/er-rel/mapsubclass3.png]

COMP3311 20T3 ♢ ER→Rel Mapping ♢ [17/17]


Produced: 15 Sep 2020