ER-to-Relational Mapping Algorithm ◼ Step 1: Mapping of Regular Entity Types. ◼ For each strong entity type E, create a relation R that includes all the non-multivalued attributes of E. ◼ Choose one of the key attributes as the primary key for R
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 2: Mapping of Weak Entity Types ◼ For each weak entity type W with owner entity type E, create a relation R & include all attributes of W as attributes of R. ◼ Also, include to R as FK, the PK attribute(s) of the relation(s) that correspond to the E. ◼ The PK of R is the combination of the PK of E and the partial key of the W, if any.
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 2: Example ◼ Create the relation DEPENDENT ◼ Include SSN, the PK of the EMPLOYEE as an FK attribute of DEPENDENT (renamed to ESSN). ◼ The PK of the DEPENDENT relation is the combination {ESSN, DEPENDENT_NAME}.
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 3: Mapping of Binary 1:1 Relationship Types ◼ R is a relationship type in the ER schema, and relations S and T correspond to the entity types participating in R. ◼ There are three possible approaches: 1. Foreign Key (2 relations) approach: In relation S, include FK for the PK of T, or vice versa ◼ Better choose entity type with total participation in R
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 3: Mapping of Binary 1:1 Relationship Types 2. Merged relation option: Merge the two entity types and the relationship into a single relation. ◼ Suitable when both participations are total
3. Relationship relation (3 relations) option: Set up
a third relation R for the purpose of cross- referencing the PKs of S and T
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 4: Mapping of Binary 1:N Relationship Types. ◼ S represents the entity type at the N-side of the relationship type R and T at the 1-side ◼ Add PK of T as attribute to S and create FK constraint in S ◼ Add attributes of the relationship type to S, if any
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 4: Example ◼ EMPLOYEE--WORKS_FOR--DEPARTMENT ◼ Dnumber, the PK of DEPARTMENT is added to EMPLOYEE as Dno and FK constraint is created
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 5: Mapping of Binary M:N Relationship Types ◼ Use Relationship-Relation approach ◼ For each M:N relationship type R, create a new relation S ◼ Include as FK attributes in S, the PKs of the relations for the participating entity types ◼ Also include any attributes of the relationship type
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 5: EMPLOYEE--WORKS_ON—PROJECT ◼ Create relation WORKS_ON ◼ The PKs of the PROJECT and EMPLOYEE relations are included as foreign keys in WORKS_ON and renamed PNO and ESSN ◼ HOURS represents the HOURS attribute of the relation type. ◼ PK is the combination of the FKs.
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 6: Mapping of Multivalued attributes. ◼ For each multivalued attribute A of entity type E, create a new relation R. ◼ R will include attributes of A and the PK of the relation for E as FK. ◼ The PK of R is the combination of A and K.
ER-to-Relational Mapping Algorithm (contd.) ◼ Step 6: Example ◼ The relation DEPT_LOCATIONS is created. ◼ DLOCATION is the multivalued attribute LOCATIONS of DEPARTMENT ◼ DNUMBER is the PK of the DEPARTMENT ◼ PK of R is {DNUMBER, DLOCATION}.