Database Systems: Transforming ERD To Rela7ons
Database Systems: Transforming ERD To Rela7ons
SYSTEMS
Transforming ERD to Rela7ons
Dr. Khalid La,f
Transforming ERD to Rela7ons
This can be done automa,cally by many CASE tools,
but it is important to understand the process
CASE tools o?en cannot model complex data
results
2
Transforma7on Steps
Step 1: Map Regular En,,es
Step 2: Map Weak En,,es
3
Step1: Mapping a Regular En7ty
Simple a?ributes: map directly onto the rela,on
(a) CUSTOMER
en7ty type with
simple a?ributes
4
Mapping a Composite A?ribute
Composite a?ributes: Only keep their cons,tuents
(a) CUSTOMER
en,ty type with
composite
aXribute
5
Handling Mul7valued A?ributes
6
Step 2: Mapping Weak En77es
Becomes a separate rela,on with a foreign
key taken from the iden,fying owner
Primary key composed of:
7
Example of mapping a weak en7ty
a) Dependent rela,on
8
Example of mapping a weak en7ty
b) Rela,ons resul,ng from weak en,ty
EMPLOYEE
Employee_ID Employee_Name
9
Mul7valued A?ributes in Regular En77es
AXributes are atomic in database systems
Mul7valued a?ribute becomes a separate rela,on
with a foreign key taken from the original en,ty
Same as for weak en,,es
Employee
EID Name
Skills
EID Skill
Onetomany rela7onship between original en7ty
and new rela7on
10
Composite Mul7valued A?ributes
The composi,on could be converted into a
separate en,ty with a many-to-many
rela,onship.
Converted to
11
Step3: Binary One-to-One Rela7onships
Primary key on the mandatory side becomes a
foreign key on the op7onal side
AXributes of
the rela,onship
also go to the
op,ons side.
12
Step3: Binary One-to-Many Rela7onships
Primary key on the one side becomes a
foreign key on the many side
Order
Order ID Order Date Customer ID
1001 20-Jun-2009 101
1002 21-Jun-2009 102
1003 21-Jun-2009 101
1004 22-Jun-2009 103
14
Step3: Binary Many-Many Rela7onships
Create a new rela,on with the primary keys
of the two en,,es as its primary key
Date_Completed
New
intersec,on
Foreign key
rela,on
Foreign key
16
Step4: Mapping Associa7ve En77es
Iden,er Assigned
17
Associa7ve En7ty without Iden7er
Iden,er NOT Assigned
19
Example Data for Unary 1:N Rela7onship
Employee and Manager
20
Step5: Mapping Unary Rela7onships
Many-to-Many leads to two rela,ons:
The original en,ty
New associa,ve rela,on in which the primary
key has two aXributes, both taken from the
primary key of the original en,ty
21
Mapping a Unary M:N Rela7onship
Contains
(a) Bill-of-materials
Quan,ty rela,onships (M:N)
22
Bill-of-Material Sample Data
Item
Item No Descrip7on Unit_Cost
101 Glass Dining Table 20,000
102 Glass 12mm 3x5 5,000
103 Wooden Pillar 1x1x2 4,000
104 Oce Table 15,000
Components
Item No Component No Quan7ty
101 102 1
101 103 2
104 102 1
23
Step6: Mapping Ternary Rela7onships
One rela,on for each en,ty and one for the associa,ve
en,ty
Associa,ve en,ty has foreign keys to each en,ty in the
rela,onship
24
Ternary Rela7onship Mapping Example
25
Transform ERD to Rela7onal Schema
26
Conclusion
Logical database model is the process of
transforming the conceptual model into
logical data model.
27