Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Translation of ER-diagram Into Relational Schema

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Translation of ER-diagram into Relational

Schema

1
Outline
1.What is a Well-structured Relation?
2. Steps to Transform E-R Diagrams into Relations
3. Converting Regular Entities into Relations
4. Converting Weak Entity types into Relations
5.Converting Unary Relationships into Relations
6.Converting Binary Relationships into Relations
7. Mapping Ternary (and n-ary) Relationships
8.Mapping Supertype/subtype relationships

2
3
1.What is a Well-structured Relation?

– A relation that contains a minimum amount of redundancy and


allows users to insert, modify and delete the rows without errors or
inconsistencies.

4
2. Steps to Transform E-R Diagrams into Relations

• It is useful to transform the conceptual data model into a set of


normalized relations
• Steps:
1. Represent entity types as relations and their attributes as the
column.
2. Represent relationships in an appropriate way
3. Normalize the relations if required
4. Merge the relations if required

5
6
3. Converting Regular Entities into Relations(1)

– Composite attributes: Use only their simple, component attributes


– Multi-valued Attribute - Becomes a separate relation with a foreign key

taken from the entity type.

7
3. Converting Regular Entities into Relations (2)

(a) Multivalued attribute becomes a separate relation

(b) 1:M relationship between original entity type and its


multivalued attribute
4. Converting Weak Entity types into Relations(1)

– Weak entity becomes a separate relation with a foreign key taken from
the strong entity type.
– The primary key is composed of:
• Partial identifier of weak entity
• Primary key of strong entity
4. Converting Weak Entity types into Relations(2)
5.Converting Unary Relationships into Relations(1)

5.1 Unary 1:N Relationships


• Relationship between instances of a single entity type
• Utilize a recursive foreign key
– A foreign key in a relation that references the primary key values
of the same relation
5.2 Unary M:N Relationships
• Create a separate relation
• Primary key of new relation is a composite of two attributes that both
take their values from the same primary key

11
5.Converting Unary Relationships to Relations(2)

Mapping a Unary 1:N


Relationship

EMPLOYEE relation with


recursive foreign key
5.Converting Unary Relationships to Relations(3)

Mapping a Unary M:N


Relationship
6.Converting Binary Relationships into Relations(1)
6.1. Binary 1:1
• Three possible options

a. Add the primary key of A as a foreign key of B


b. Add the primary key of B as a foreign key of A
c. Both

PASSENGER 1 HAS 1 TICKET

14
6.Converting Binary Relationships into Relations(2)

• In an One-to-One relationship, two tables may be collapsed into one


table to avoid redundancy issues

PASSENGER TICKET

PID Primary Key TID

NAME DEPARTURE

ADDRESS
Foreign Key PID

15
6.Converting Binary Relationships into Relations(3)

6.2 Binary 1:N Relationships


• Add the primary key attribute (or attributes) of the entity type on the “ONE” side of
the relationship as a foreign key into the relation on the “MANY” side.

• The primary key on the “one” side migrates to the “many” side . The foreign key is
always added into the “Many” side

16
6.Converting Binary Relationships into Relations(4)

Example 1

INSTRUCTOR Teach Course

Instructor
InstructorID Primary Key CourseSection
FirstName CNAME
Office CID
Department
Semester
Foreign Key TeacherID
17
6.Converting Binary Relationships into Relations(5)

Example 2

Department has Employee

Department Employee

DeptID Primary Key EmpID

DeptName DeptID
Foreign Key
Location EmpName

18
6.Converting Binary Relationships into Relations(6)

6.3 Binary M:N relationships


• Create a new table that has a primary key which is the combination
of the primary keys of all the participating entity types . Those
added primary keys also act as foreign keys in the new table .
• All descriptive attributes of the relationship type between/among
the participating entity types must also be included in the new
table.
• The primary key must satisfy the following two conditions
a. The value of the key must uniquely identify every row in the
relation
b. The key should be non redundant

19
M:N Relationship Example 1
M:N Relationship Example 2
Transforming N:M Example 2

Orders OrderLine Parts


1:N
OrderNum OrderNum PartNum
OrderDate PartNum Description
N:1
CustomerNum NumOrdered Class
Price

• Binary many-to-many relationships are designed as two One-to-Many


relationships
– Create an intersection table with the primary key from each
original table as foreign keys
– The intersection table usually has a composite primary key
22
7. Mapping Ternary (and n-ary) Relationships

– One relation for each entity and one for the associative entity.
– Associative entity has foreign keys to each entity in the relationship.
7. Mapping a Ternary relationship into relations
8.Mapping Supertype/subtype relationships(1)
7.Mapping Supertype/subtype relationships(2)
End of Chapter 3

• If you have and Queries?

27

You might also like