Relational Database Design by ER- and EER-to- Relational Mapping ▪ Design a relational database schema ▪ Based on a conceptual schema design ▪ Seven-step algorithm to convert the basic ER model constructs into relations
ER-to-Relational Mapping Algorithm ▪ COMPANY database example ▪ 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
ER-to-Relational Mapping Algorithm (cont’d.) ▪ 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
ER-to-Relational Mapping Algorithm (cont’d.) ▪ 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 • Crossreference or relationship relation approach
Mapping M:N Relationship ▪ 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
ER-to-Relational Mapping Algorithm (cont’d.) ▪ Step 6: Mapping of Multivalued Attributes ▪ 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