Assume that the mapping will create tables with simple single- valued attributes Step 1: Mapping of Regular Entity Types For each regular entity type, create a relation R that includes all the simple attributes of E Called entity relations • Each tuple represents an entity instance • Ex: Employee. Department and Project
ER-to-Relational Mapping Algorithm Step 2: Mapping of Weak Entity Types For each weak entity type, create a relation R and include all simple attributes of the entity type as attributes of R Include primary key attribute of owner as foreign key attributes of R Ex: Dependent
Step 3: Mapping of Binary 1:1 Relationship Types
For each binary 1:1 relationship type • Identify relations that correspond to entity types participating in R Possible approaches: • Foreign key approach • Merged relationship approach • Cross-reference or relationship relation approach
Choose one of the relations—S, say—and include as a foreign key in S the primary key of T. It is better to choose an entity type with total participation in R in the role of S. Include all the simple attributes (or simple components of composite attributes) of the 1:1 relationship type R as attributes of S. Ex: Employee – Manages – department (Total Participation) Merged relationship approach An alternative mapping of a 1:1 relationship type is to merge the two entity types and the relationship into a single relation. This is possible when both participations are total Cross-reference or relationship relation approach The third option is to set up a third relation R for the purpose of cross-referencing the primary keys of the two relations S and T representing the entity types.
Step 4: Mapping of Binary 1:N Relationship Types
Foreign key approach For each regular binary 1:N relationship type • Identify relation that represents participating entity type at N-side of relationship type • Include primary key of other entity type as foreign key in S • Include simple attributes of 1:N relationship type as attributes of S • To apply this approach to our example, we map the 1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION For WORKS_FOR we include the primary key Dnumber of the DEPARTMENT relation as foreign key in the EMPLOYEE relation and call it Dno.
Step 5: Mapping of Binary M:N Relationship Types
For each binary M:N relationship type • Create a new relation S • Include primary key of participating entity types as foreign key attributes in S • Include any simple attributes of M:N relationship type
For each multivalued attribute • Create a new relation • Primary key of R is the combination of A and K • If the multivalued attribute is composite, include its simple components
For each n-ary relationship type R • Create a new relation S to represent R • Include primary keys of participating entity types as foreign keys • Include any simple attributes as attributes
Summary Map conceptual schema design in the ER model to a relational database schema Algorithm for ER-to-relational mapping Illustrated by examples from the COMPANY database Include additional steps in the algorithm for mapping constructs from EER model into relational model