0% found this document useful (0 votes)
130 views45 pages

8 Mapping ERD To Relations

Here is an E-R diagram for the scenario described: [ER DIAGRAM] Entity Types: - Person - Exam - License Relationships: - Takes - Person takes Exam - Issues - Exam issues License - Holds - Person holds License Attributes: Person: personID, name, etc. Exam: examID, date, location, result License: licenseNumber, type, expiryDate, restriction, driverEducation The E-R diagram models the entities involved (Person, Exam, License), and the relationships between them - a Person Takes an Exam, an Exam Issues a License, and a Person H

Uploaded by

tembo saidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views45 pages

8 Mapping ERD To Relations

Here is an E-R diagram for the scenario described: [ER DIAGRAM] Entity Types: - Person - Exam - License Relationships: - Takes - Person takes Exam - Issues - Exam issues License - Holds - Person holds License Attributes: Person: personID, name, etc. Exam: examID, date, location, result License: licenseNumber, type, expiryDate, restriction, driverEducation The E-R diagram models the entities involved (Person, Exam, License), and the relationships between them - a Person Takes an Exam, an Exam Issues a License, and a Person H

Uploaded by

tembo saidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Reducing ER Diagram to Relation

• To implement the database, it is necessary


to use the relational model.
• There is a simple way of mapping from ER
model to the relational model.

ZICTC@2019 1
Mapping Algorithm

• The mapping algorithm gives the procedure


to map ER diagram to relations.
• The rules in mapping algorithm are given as:

ZICTC@2019 2
Mapping Regular Entities
• Each regular entity type in an ER diagram is
transformed into a relation.
• The name given to the relation is generally
the same as the entity type.
• Each simple attribute of the entity type
becomes an attribute of the relation.
• The identifier of the entity type becomes the
primary key of the corresponding
• relation.
ZICTC@2019 3
PLAYER

ZICTC@2019 4
Converting Composite Attribute in
an ER Diagram to Relations

ZICTC@2019 5
Mapping Multivalued Attributes in
ER Diagram to Relations
• In this example, the skill associated with the
EMPLOYEE is a multivalued attribute, since
an EMPLOYEE can have more than one
skill as fitter, electrician,turner, etc.

ZICTC@2019 6
ZICTC@2019 7
Converting “Weak Entities” in ER
Diagram to Relations
• For each weak entity type, create a new relation
and include all of the simple attributes as attributes
of the relation.
• Then include the primary key of the identifying
relation as a foreign key attribute to this new
relation.
• The primary key of the new relation is the
combination of the primary key of the identifying
and the partial identifier of the weak entity type.

ZICTC@2019 8
ZICTC@2019 9
Converting Binary Relationship to
Relation
• A relationship which involves two entities
can be termed as binary relationship.
• This binary relationship can be one-to-one,
one-to-many, many-to-one, and many-to-
many.

ZICTC@2019 10
Mapping one-to-Many Relationship
• For each 1–M relationship, first create a
relation for each of the two entity type’s
participation in the relationship.

ZICTC@2019 11
ZICTC@2019 12
• Binary one-to-one relationship can be
viewed as a special case of one-to-many
relationships.
• The process of mapping one-to-one
relationship requires two steps.
• First, two relations are created, one for each
of the participating entity types.
• Second, the primary key of one of the
relations is included as a foreign key in the
other relation.

ZICTC@2019 13
Mapping Associative Entity to
Relations
• Many-to-many relationship can be modeled
as an associative entity in the ER diagram.

ZICTC@2019 14
Without Identifier

ZICTC@2019 15
ZICTC@2019 16
With Identifier

• Sometimes data models will assign an


identifier (surrogate identifier) to the
associative entity type on the ER diagram.

ZICTC@2019 17
ZICTC@2019 18
ZICTC@2019 19
Converting Unary Relationship to
Relations
• Unary relationships are also called recursive
relationships.
• The two most important cases of unary
relationship are one-to-many and many-to-
many.

ZICTC@2019 20
One-to-many Unary Relationship

• Each employee has exactly one manager. A


given employee may manage zero to many
employees. The foreign key in the relation is
named Manager-ID.
• This attribute has the same domain as the
primary key Employee-ID.

ZICTC@2019 21
ZICTC@2019 22
Converting Ternary Relationship to
Relations
• A ternary relationship is a relationship
among three entity types.
• The three entities given in this example are
PATIENT, PHYSICIAN, and TREATMENT.
• The PATIENT–TREATMENT is an
associative entity.

ZICTC@2019 23
ZICTC@2019 24
ZICTC@2019 25
Example – N-ary Relationship Set

ZICTC@2019 26
Converting EERD to Relational

• 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.
• The subclass PK is the same as the one for
the superclass entity.
• Add all other specific attributes.

ZICTC@2019 27
disjoint optional

ZICTC@2019 28
Step 3a Results

• EMPLOYEE (SSN, FNAME, MINT,


LNAME,...);
• SECRETARY (SSN, TYPINGSPEED);
• TECHNICIAN (SSN, TGRADE);
• ENGINEER (SSN, ENGTYPE);

ZICTC@2019 29
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.

ZICTC@2019 30
disjoint mandatory

• EG
EMPLOYEE

SALARIED- HOURLY-
EMPLOYEEE EMPLOYEE

ZICTC@2019 31
Step 3b Results

• SALARIED_EMPLOYEE (SSN, SALARY,


FNAME, MINT, LNAME,...);
• HOURLY_EMPLOYEE (SSN, PAYSCALE,
FNAME, MINT, LNAME,...);

ZICTC@2019 32
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.

ZICTC@2019 33
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).

ZICTC@2019 34
overlapping optional

• EG
EMPLOYEE

SECRETARY TECHNICIAN ENGINEER

ZICTC@2019 35
Step 3c Result

• EMPLOYEE (SSN, FNAME, MINT, LNAME,


… JOBTYPE , TYPINGSPEED, TGRADE,
ENGTYPE).
OR
• EMPLOYEE (SSN, FNAME, MINT, LNAME,
…,
• EMP_JOB (SSN, TYPINGSPEED,
TGRADE, ENGTYPE)

ZICTC@2019 36
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.

ZICTC@2019 37
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”.

ZICTC@2019 38
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).

ZICTC@2019 39
overlapping mandatory

PART

MANUFACTURED PURCHASED
PART PART

ZICTC@2019 40
Step 3d Result

• PART (PartNo, Description,


MFlag, DrawingNo, ManufactureDate,
BatchNo,
PFlag, SupplierName, ListPrice);

ZICTC@2019 41
ZICTC@2019 42
ZICTC@2019 43
Question:
• RTSA administers driving tests and issues
driver’s licenses. Any person who wants a
driver’s license must first take a learner’s
exam at any RTSA Branch in the province.
• If he/she fails the exam, he can take the
exam again any time after a week of the
failed exam date, at any branch. If he
passes the exam, he is issued a license
(type = learner’s) with a unique license
number.

ZICTC@2019 44
• A learner’s license may contain a single
restriction on it. The person may take his
driver’s exam at any RTSA branch any
time before the learner’s license expiry
date (which is usually set at six months
after the license issue date).
• If he passes the exam, the branch issues
him a driver’s license. A driver’s license
must also record if the driver has
completed driver’s education, for
insurance purposes.
• Create a E-R diagram.
ZICTC@2019 45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy