Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping
Mapping from conceptual model (EER-M) into a relational schema
description
Transcript of Mapping from conceptual model (EER-M) into a relational schema
![Page 1: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/1.jpg)
prepared by chaamwe 1
•Mapping from conceptual model (EER-M) into a relational schema
![Page 2: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/2.jpg)
Lifecycle of Database system development
![Page 3: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/3.jpg)
prepared by chaamwe 3
Mapping an EER-Modelinto a relational schema
This approach involves applying transformation rules (or steps) to the EER model in order to achieve a relational logical schema.
NB: the steps below should not be taken as golden rules.
![Page 4: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/4.jpg)
Mapping an EER-Modelinto a relational schema
Application requirements vary from one domain to another and from one user to another.
Hence, the following steps should be only taken as guidelines
![Page 5: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/5.jpg)
![Page 6: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/6.jpg)
prepared by chaamwe 6
Step 1
For each regular entity type (ignore those with subclasses at this point) on your diagram
create a table and nominate a primary key (PK) for that relation.
![Page 7: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/7.jpg)
Step 1 Cont:
![Page 8: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/8.jpg)
prepared by chaamwe 8
Step 2:
For each weak entity type, create a relation.
The PK is a combination of the identifier of the parent entity and the identifier of the weak or dependent entity (i.e. a composite PK).
![Page 9: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/9.jpg)
Step 2 cont
![Page 10: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/10.jpg)
prepared by chaamwe 10
Step 4:
Each unary or binary type relationship with a one-to-one cardinality is mapped by placing a foreign key attribute in one of the relational as the linking attribute.
If the relationship is mandatory OR optional from both sides,
then it does not make a difference as to where to place the foreign key.
![Page 11: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/11.jpg)
prepared by chaamwe 11
Step 4 Cont:
If it is mandatory (total participation) from one side and optional (partial participation) from the other side,
then the PK of the optional side is inserted as a foreign key at the mandatory side.
![Page 12: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/12.jpg)
Step 4 cont:
![Page 13: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/13.jpg)
prepared by chaamwe 13
Step 5:
For Each unary or binary one-to-many relationship type.
The PK from the 1-end is inserted as a FK at the N-end.
![Page 14: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/14.jpg)
Step 5 cont:
![Page 15: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/15.jpg)
prepared by chaamwe 15
Step 6:
Each N:M relationship of any degree is mapped to a new linking relation whose PK includes the keys of all participating relations (a composite PK).
Include all relationship’s attributes in the new relation.
![Page 16: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/16.jpg)
Step 6 cont:
![Page 17: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/17.jpg)
prepared by chaamwe 17
Step 7:
Each multi-value attribute mapped to a new relation.
The new relation should include an attribute pertaining to the main relation as a foreign key.
![Page 18: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/18.jpg)
Step 7 cont:
![Page 19: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/19.jpg)
Step 3.0 If we have a single optional
(always!) subtype then: Create a relation for the superclass and
identify a PK for it; Create a relation for the single
subtype. The Subtype’s PK is the same as the
one for the Superclass entity. Add all other specific attributes to the
subclass.
![Page 20: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/20.jpg)
Example
![Page 21: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/21.jpg)
Step 3/ Multi Subclasses If we have more than one subtype,
there are four different possibilities, depends on Business Rules (Constraints).
These are: Disjoint Optional Disjoint Mandatory Overlapping Optional Overlapping Mandatory
![Page 22: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/22.jpg)
prepared by chaamwe 22
Step 3a:
If the participation is disjoint optional, then create a relation for the superclass and identify a PK for it.
You also need to create a relation for each subclass.
![Page 23: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/23.jpg)
Step 3a: cont
The subclass PK is the same as the one for the superclass entity.
Add all other specific attributes.
![Page 24: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/24.jpg)
prepared by chaamwe 24
disjoint optional
EMPLOYEE
SECRETARY TECHNICIAN ENGINEER
D
![Page 25: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/25.jpg)
prepared by chaamwe 25
Step 3a Results
EMPLOYEE (SSN, FNAME, MINT, LNAME,...);
SECRETARY (SSN, TYPINGSPEED); TECHNICIAN (SSN, TGRADE); ENGINEER (SSN, ENGTYPE);
![Page 26: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/26.jpg)
prepared by chaamwe 26
Step 3b:
If the participation is disjoint mandatory, then create a relation for each of the subclasses (no relation for the superclass)
with the same PK you have chosen earlier for the superclass.
Add all the specific attributes to the appropriate subclass.
![Page 27: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/27.jpg)
prepared by chaamwe 27
disjoint mandatory
EG EMPLOYEE
SALARIED-EMPLOYEEE
HOURLY-EMPLOYEE
D
![Page 28: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/28.jpg)
prepared by chaamwe 28
Step 3b Results
SALARIED_EMPLOYEE (SSN, SALARY, FNAME, MINT, LNAME,...);
HOURLY_EMPLOYEE (SSN, PAYSCALE, FNAME, MINT, LNAME,...);
![Page 29: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/29.jpg)
prepared by chaamwe 29
Step 3c: If the participation is overlapping
optional, then create a single relation to represent the superclass and all its subclasses.
Identify the PK, as well as, a type or flag attribute to specify class membership.
The type attribute is used to indicate the participation occurrences of the superclass in the subclasses.
![Page 30: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/30.jpg)
prepared by chaamwe 30
Overlapping Optional
The mapping is not recommended if many specific attributes are defined at the subclass, or
if the subclasses are involved in relationships among themselves or with other entities.
In these cases, this option should be treated as a disjoint optional (step 3a).
![Page 31: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/31.jpg)
prepared by chaamwe 31
overlapping optional
EG EMPLOYEE
SECRETARY TECHNICIAN ENGINEER
O
![Page 32: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/32.jpg)
prepared by chaamwe 32
Step 3c Result EMPLOYEE (SSN, FNAME, MINT,
LNAME, … JOBTYPE , TYPINGSPEED, TGRADE, ENGTYPE).
OR EMPLOYEE (SSN, FNAME, MINT,
LNAME, …, EMP_JOB (SSN, TYPINGSPEED,
TGRADE, ENGTYPE)
![Page 33: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/33.jpg)
prepared by chaamwe 33
Step 3d
The overlapping mandatory case. In this case you need to create a
single relation to represent the superclass and all it subclasses.
Identify the PK as well as a type or flag attribute to specify class membership.
![Page 34: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/34.jpg)
Step 3d cont:
If the flag is “on” for a specific subclass means that the superclass has a specialisation.
At least one of the flags should be “on”.
Other flags could be “on” or “off”.
![Page 35: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/35.jpg)
prepared by chaamwe 35
overlapping mandatory
The mapping is not recommended if many specific attributes are defined at the subclass, or
if the subclasses are involved in relationships among themselves or with other entities.
In these cases, this option should be treated as a disjoint optional (step 3a).
![Page 36: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/36.jpg)
prepared by chaamwe 36
overlapping mandatory
EG1 PART
MANUFACTUREDPART
PURCHASED PART
O
![Page 37: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/37.jpg)
prepared by chaamwe 37
Step 3d Result
PART (PartNo, Description,MFlag, DrawingNo, ManufactureDate, BatchNo,PFlag, SupplierName, ListPrice);
![Page 38: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/38.jpg)
prepared by chaamwe 38
Other rules
There are few semantic concepts that exist in the EER model that
need to be resolved in order to be mapped easily into a relational logical model.
![Page 39: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/39.jpg)
prepared by chaamwe 39
Remove Complex Relationship
This step involves removing or decomposing any relationship of degree d,
where d is greater than two into d one-to-many relationships linked via a weak entity type.
![Page 40: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/40.jpg)
prepared by chaamwe 40
A ternary relationship
TENANT
STAFFPROPERTY LEASES
![Page 41: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/41.jpg)
prepared by chaamwe 41
A Decomposed ternary relationship
LEASE AGREEMENT
TENANT
PROPERTY STAFF
HOLDS
ASSOCIATED WITH ORGANISESLEASE AGREEMENT
![Page 42: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/42.jpg)
prepared by chaamwe 42
Remove Recursive Relationships
This step is to decompose any recursive relationship by creating a weak entity type
![Page 43: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/43.jpg)
prepared by chaamwe 43
Recursive Relationships
Employee supervises
![Page 44: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/44.jpg)
prepared by chaamwe 44
Recursive Relationships
Employee Allocated Staff
supervises
Supervised by
Allocated Staff
![Page 45: Mapping from conceptual model (EER-M) into a relational schema](https://reader036.fdocuments.us/reader036/viewer/2022062301/56813b26550346895da3e4e6/html5/thumbnails/45.jpg)
prepared by chaamwe 45