Relational Database Design by ER and EER-to-Relational Mapping Flashcards
STEP 1: Mapping of Strong Entity Types
For each strong (regular) entity type E:
- Create a relation R that includes all the atomic attributes. This can also
be called an entity relation.
o If there are composite attributes, include only their corresponding
atomic attributes. - Choose one of the key/s of E as the primary key for R. It will remain underlined and will be listed first in the relation.
o If the chosen key is composite, then the set of its corresponding atomic attributes will form the primary key.
o If multiple keys were identified for E in the ER model, the
unselected key/s will be documented as unique key/s but they will NOT be underlined in the relation anymore.
Step 2: Mapping of Weak Entity Types
For each weak entity type W with owner entity type E:
- Create a relation R that includes all the atomic attributes (or corresponding atomic attributes of composite attributes) of W.
- Include the primary key of E. It and the partial key of W (if any) will form the primary key of R which is underlined and listed first in the relation.
o Note that this primary key of E that was included in R is also a
foreign key and will be documented as such.
Ex: DEPENDENT(** Ssn, Dependent name**, Sex, Birth date, Relationship )
3 Approaches in Mapping of Binary 1:1 Relationship Types
- Foreign key approach
<- Preferred - Merged relation approach
- Cross-reference approach
Step 3 (for 1:1): Foreign Key Approach
With R, S and T identified:
- Choose one of the relations (preferably one with total participation), say S,
and include as foreign key in S the primary key of T. - Include all the atomic attributes (or corresponding atomic attributes of
composite attributes) of the 1:1 relationship type R as attributes of S.
Step 3 (for 1:1): Merged Relation Approach
This is only possible when both participations are total. With R, S and T identified:
- Merge S and T into a single relation U.
- Include all the atomic attributes (or corresponding atomic attributes of
composite attributes) of the 1:1 relationship type R as attributes of U. - Pick one of the primary keys from the original relations as the primary key of U. The other key will be a unique key and will be documented as such.
NOTE: This approach cannot be done if there are additional relationships between the original relations which prevent the merge into a single relation.
Step 3 (for 1:1): Cross-reference Approach
This is also called relationship relation approach and more appropriate when both participations are partial. With R, S and T identified:
- Create a 3rd relation U containing both primary keys from S and T as foreign keys. This will be sort of a lookup table.
- Include all the atomic attributes (or corresponding atomic attributes of composite attributes) of the 1:1 relationship type R as attributes of U.
- Pick one of the primary keys from the original relations as the primary key of U. The other key will be a unique key and will be documented as such.
NOTE: The obvious disadvantage of this approach is the extra relation which requires extra join operation/s.
Step 4: Mapping of Binary 1:N Relationship Types
For each binary 1:N relationship type R:
- Identify the relation S that represents the participating entity type on the
N − side of the relationship type. - Include as foreign key in S the primary key of T that represents the other participating entity type (on the 1 − side).
- Include all the atomic attributes (or corresponding atomic attributes of
composite attributes) of the 1:N relationship type R as attributes of S.
Step 5: Mapping of Binary M:N Relationship Types
For each binary M:N relationship type R:
- Create a new relation S to represent R.
- Include as foreign keys in S the primary keys of the relations that represent the participating entity types.
- Include all the atomic attributes (or corresponding atomic attributes of
composite attributes) of the M:N relationship type R as attributes of S. - All those added in #2 and #3 above will form the primary key of S and will need to be underlined.
Step 6: Mapping of Multivalued Attributes
For each multivalued attribute A:
- Create a new relation R.
- Include as foreign key in R the primary key of the relation that
represents the entity type or relationship type that has A as attribute. - Include an atomic attribute in R corresponding to single value of A. If A is composite, include its corresponding atomic attributes instead.
- All those added in #2 and #3 above will form the primary key of R and will need to be underlined.
ex: DEPT_LOCATION( Dnumber, Dlocation )
Step 7: Mapping of N-ary Relationship Types
For each n-ary relationship type R (where n > 2):
- Create a new relationship relation S to represent R.
- Include as foreign keys in S the primary keys of the relations that represent the participating entity types.
- Include any atomic attributes (or corresponding atomic attributes of composite attributes) of R as attributes of S.
- All those added in #2 and #3 above will form the primary key of S and will need to be underlined.
Ex.
SUPPLIER( Sname )
PART( Part no )
PROJECT( Proj name )
SUPPLY( Sname, Part no, Proj name, Quantity )
Mapping of Specialization / Generalization, 4 common options to convert a specialization (generalization)
into relation schemas:
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
Option 8A: Multiple Relations – Superclass and Subclasses
This option works for ANY specialization (Disjoint/Overlapping Disjointedness,
Total/Partial Specialization)
- Create a new relation for the superclass (with all its attributes).
- For each of subclass:
a. Create a new relation for the subclass with the primary key of the superclass as its primary key (also a foreign key).
b. Include the local attributes of the subclass in the new relation.
Ex.
EMPLOYEE( Ssn, Fname, Minit, Lname, Birth date, Address, Job type )
SECRETARY( Ssn, Typing speed )
TECHNICIAN( Ssn, Tgrade )
ENGINEER( Ssn, Eng type )
Option 8B:
Multiple Relations – Subclass Relations Only
This option works only for Total specializations and recommended for Disjoint
Disjointedness because those with Overlapping Disjointedness may have same entity duplicated in several relations.
For each subclass:
1. Create a new relation for the subclass.
2. Include all attributes of the superclass in the new relation; The primary key of the new relation is the same as that of the superclass.
3. Include the local attributes of the subclass in the new relation.
Option 8C:
Single Relation with One Type Attribute
This option works only for Disjoint Disjointedness.
- Create a new relation for the superclass (with all its attributes).
- Include a type (or discriminating) attribute in the new relation; Its value
will indicate the subclass the tuple belongs to (if any). - For each of subclass, include its local attribute/s in the new relation.
NOTE: The drawback to this is the potential for generating many NULL values
if many local attributes exist in the subclasses.
ex. EMPLOYEE( Ssn, Fname, Minit, Lname, Birth date, Address, Job type, Typing speed, Tgrade, Eng type )
Option 8D: Single Relation with Multiple Type Attribute
This option works for ANY specialization but more appropriate for those with
Overlapping Disjointedness.
- Create a new relation for the superclass (with all its attributes).
- For each subclass:
a. Include a Boolean type attribute in the new relation indicating whether
or not the tuple belongs to the subclass
b. Include the local attribute/s of the subclass in the new relation.
NOTE: Same drawback as the previous option.
Ex. PART( Part no, Description, Is manufactured, Drawing no, Batch no, Manufacture date, Is purchased, Supplier name, List price )
An option in Mapping of Specialization / Generalization that works for any specialization
Option A Superclass and Subclasses
An option in Mapping of Specialization / Generalization that only works for Total Specializations and recommended for Disjoin Disjointedness
Option B Subclass Relations Only
This option works only for Disjoint Disjointedness.
Option 8C:
Single Relation with One Type Attribute
This option works for ANY specialization but more appropriate for those with
Overlapping Disjointedness.
Option 8D:
Single Relation with Multiple Type Attribute
Step 9: Mapping of Union Types (Categories)
- Create a new relation U for the Union Type with all its attributes.
- Include a surrogate key in U and make it the primary key of the relation.
- Include a type attribute to indicate the particular entity type to which the
tuple belongs to. - For each superclass:
a. Create a new relation Si for the superclass (with its attributes).
b. Include as foreign key in Si
the surrogate key to specify the
correspondence between it and the original key of Si
Ex:
PERSON( Ssn, Driver license no, Name, Address, Owner id )
BANK( Bname, Baddress, Owner id )
COMPANY( Cname, Caddress, Owner id )
OWNER( Owner id, Owner type)
is another term if the keys happen to be the row ids or sequential numbers.
Surrogate Keys