Module 2: ER to Relation Mapping
Steps for mapping
1. Regular Entity
For each entity type
- Create a relation
- Choose a key as the primary key
- Include all simple attributes (e.g., a3 and a4) which are not composite (e.g.,a2), derived or multivalued (e.g., a5)
2. Weak Entity
For each weak entity type
- Create a relation
- Set its primary key as the combination of the primary keys of owner entities and its own partial key.
- Include a foreign key from the relation to the primary key of the relation of its owner entity types.
- Include all simple attributes which are not composite, derived or multivalued.
3. Binary 1:1 Relationship
For each binary 1:1 relationship type
- Choose one of the participating entity types (preference is given to entity types with total participation)
- Include a foreign key from the chosen entity type back to the primary keys of the relation of the other entity type.
- Include all the simple attributes of the relationship type to the relation of the chosen entity type.
Step 4. Binary 1:N Relationship
For each (non-weak) binary 1:N relationship type
- Identify the participating entity type at the N-side of the relationship type
- Include a foreign key to the entity type on the N-side. This foreign key should be the primary key of the entity type on the 1-side.
- Include any simple attributes of the relationship type as attributes of the relation of the N side.
Step 5. Binary M:N Relationship
For each binary M:N relationship type
- Create a new relation
- Include foreign keys from relation to the primary key of the participating entity types
- The combination of foreign keys will form the primary key of R
- R can have its own attributes that contribute to the primary key
- Include any simple attributes of R as attributes of the new relation
Step 6: Multivalued Attributes
For each multivalued attribute:
- Create a new relation.
- Include a foreign key from the relation to the primary key of the associated entity type.
- The primary key is the combination of the multivalued attributes and the primary key of its associated entity type.
- If the multivalued attribute is composite, include its simple components.
Step 7: N-ary Relationships
For each N-ary relationship type
- Create a new relation
- Include foreign keys from the relation to the primary key of the participating entity types
- The combination of foreign keys from entity types with many cardinality will form the primary key
- R can have its own attributes that contribute to the primary key
- Include any simple attributes of R as attributes of the new relation
Step 8: Super and Subclasses Mapping
The following method works for total/partial and disjoint/overlapping subclasses. For each subclass entity type
- Create a relation
- The primary key of each of the subclasses is the primary key of the superclass.
- Include a foreign key from the relation to the primary key of the relation of its superclass entity type.
- Include all simple attributes which are not composite, derived or multivalued.