Database - Discussions

profileSan77
Chapter09_RelationalDatabaseDesignbyER-andERR-to-RelationalMapping.pdf

Relational Database Design by ER- and ERR-to-

Relational Mapping

Dr. Buleje

Outline

◼ ER-to-Relational Mapping Algorithm ◼ Step 1: Mapping of Regular Entity Types

◼ Step 2: Mapping of Weak Entity Types

◼ Step 3: Mapping of Binary 1:1 Relation Types

◼ Step 4: Mapping of Binary 1:N Relationship Types.

◼ Step 5: Mapping of Binary M:N Relationship Types.

◼ Step 6: Mapping of Multivalued attributes.

◼ Step 7: Mapping of N-ary Relationship Types.

◼ Mapping EER Model Constructs to Relations ◼ Step 8: Options for Mapping Specialization or Generalization.

◼ Step 9: Mapping of Union Types (Categories).

Mapping

GOALS

◼ Preserve all information

◼ Maintain the constraints to the extent possible

◼ Minimize null values

ER-to-Relational Mapping Algorithm

◼ Step 1: Mapping of Regular Entity Types.

◼ Example: ◼ We create the relations EMPLOYEE, DEPARTMENT, and

PROJECT in the relational schema corresponding to the regular entities in the ER diagram.

Figure 9.1 The ER conceptual schema diagram for the COMPANY database.

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 2: Mapping of Weak Entity Types

◼ Example: ◼ Create the relation DEPENDENT in this step to correspond

to the weak entity type DEPENDENT. ◼ Include the primary key SSN of the EMPLOYEE relation as a foreign

key attribute of DEPENDENT (renamed to ESSN).

◼ The primary key of the DEPENDENT relation is the combination {ESSN, DEPENDENT_NAME} because DEPENDENT_NAME is the partial key of DEPENDENT.

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 3: Mapping of Binary 1:1 Relation Types

◼ There are three possible approaches: 1. Foreign Key ( 2 relations) approach

Example:

1:1 relation MANAGES is mapped by choosing the participating entity type DEPARTMENT to serve in the role of S, because its participation in the MANAGES relationship type is total.

2. Merged relation (1 relation) option

3. Cross-reference or relationship relation ( 3 relations) option

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 4: Mapping of Binary 1:N Relationship Types.

◼ Example: 1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION in the figure.

◼ For WORKS_FOR we include the primary key DNUMBER of the DEPARTMENT relation as foreign key in the EMPLOYEE relation and call it DNO.

◼ An alternative approach is to use a Relationship relation (cross referencing relation)

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 5: Mapping of Binary M:N Relationship Types. ◼ Example: The M:N relationship type WORKS_ON from the ER

diagram is mapped by creating a relation WORKS_ON in the relational database schema.

◼ The primary keys of the PROJECT and EMPLOYEE relations are included as foreign keys in WORKS_ON and renamed PNO and ESSN, respectively.

◼ Attribute HOURS in WORKS_ON represents the HOURS attribute of the relation type.

◼ The primary key of the WORKS_ON relation is the combination of the foreign key attributes {ESSN, PNO}.

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 6: Mapping of Multivalued attributes.

◼ Example: The relation DEPT_LOCATIONS is created. ◼ The attribute DLOCATION represents the multivalued attribute

LOCATIONS of DEPARTMENT, while DNUMBER-as foreign key- represents the primary key of the DEPARTMENT relation.

◼ The primary key of R is the combination of {DNUMBER, DLOCATION}.

ER-to-Relational Mapping Algorithm (contd.)

◼ Step 7: Mapping of N-ary Relationship Types.

◼ Example:

◼ The relationship type SUPPY in the ER on the next slide. ◼ This can be mapped to the relation SUPPLY shown in the relational

schema, whose primary key is the combination of the three foreign keys {SNAME, PARTNO, PROJNAME}

Summary of Mapping constructs and

Constraints

Mapping of Generalization and

Specialization Hierarchies

to a Relational Schema

Mapping EER Model Constructs to

Relations

◼ Step8: Options for Mapping 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 8A: Multiple relations-Superclass and subclasses

◼ Option 8B: Multiple relations-Subclass relations only

◼ Option 8C: Single relation with one type attribute

◼ Option 8D: Single relation with multiple type attributes

Mapping EER Model Constructs to

Relations (contd.)

◼ Step 9: Mapping of Union Types (Categories).

◼ Surrogate Key

Chapter Summary

◼ ER-to-Relational Mapping Algorithm ◼ Step 1: Mapping of Regular Entity Types

◼ Step 2: Mapping of Weak Entity Types

◼ Step 3: Mapping of Binary 1:1 Relation Types

◼ Step 4: Mapping of Binary 1:N Relationship Types.

◼ Step 5: Mapping of Binary M:N Relationship Types.

◼ Step 6: Mapping of Multivalued attributes.

◼ Step 7: Mapping of N-ary Relationship Types.

◼ Mapping EER Model Constructs to Relations ◼ Step 8: Options for Mapping Specialization or Generalization.

◼ Step 9: Mapping of Union Types (Categories).