You are on page 1of 9

Relational DB Design

ER-to-Relational mapping

Dr. Yousry Taha


CS 322

(This is the instructor’s notes and student has to


read the textbook for complete material.)
Mapping ER Schema to its
corresponding Relational Schema can
follow these steps

1- For each regular entity E in ER:


– create a Relation R includes all simple
attributes of E.
– Composite attributes of E are represented by
their simple attributes only in R.
– The key of R is one of the keys of E.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Mapping of Weak Entity
2. For each weak entity W in ER:
– Create a relation R includes all the simple attributes of W.

– Composite attributes are treated as in step1.

– Include the primary key of the owner (identifying) entity as a


foreign key in R.

– The primary key of R is the combination of the partial key of


W and the foreign key.

– It is common to use the (CASCADE) option on the foreign


key for both ON UPDATE and ON DELETE
CS 322 (ER to Relational Mapping) - Dr. Yousry Taha
Mapping of 1:1 Relationship
3. For each 1:1 relationship R in the ER:

– Identify the relations S and T that correspond to


the entity types participating in R.
– Choose one of the relations and include its
primary key as a foreign key in the other.
– It is better to select the entity of total participation
to include the primary key of the other (partial
participation) as a foreign key in it.
– If both participations are total, it is appropriate to
merge them into one relation.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Mapping of 1:N Relationship
4. For each regular binary 1:N relationship R:

– Identify the relation S that represents the entity at


N-side of the relation.

– Include as a foreign key in S the primary key of


the other relation that participates in R.

– Include any simple attributes in R into S.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Mapping of M:N Relationship
5. For each regular binary M:N relationship R:

– Create new relation S to represent R.


– Include as a foreign key in S the primary keys of
the relations that participate in R.
– Include any simple attributes in R into S.
– The primary key of S is the combination of the
primary keys of the participating entities.
– CASCADE option should be used on the foreign
key of S for both ON UPDATE and ON DELTE.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Mapping of n-ary Relationship
6. For each n-ary relationship R:

– Create new relation S.


– Include as foreign key attributes in S the primary
keys of the relations that participate in R.
– Include any attributes of R as attributes of S.
– The primary key of R is the combination of all the
foreign keys that reference the participating entity
in R.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Mapping of Multivalued Attributes
7. For each multivalued attribute A:

– Create new relation R.


– Include an attribute corresponding to A into R.
– Include as a foreign key (K) in R the primary key
of the relation that has A as attribute.
– The primary key of R is the combination of the A
and K.
– CASCADE option should be used on the foreign
key of R for both ON UPDATE and ON DELTE.

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha


Employee ERD
EMPLOYEE
FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO

Department
DNAME DNUMBER MGRSSN MGRSTARTDATE

DEPT_LOCATIONS
DNUMBER DLOCATION

PROJECT
PNAME PNUMBER PLOCATION DNUM

WORKS_ON
ESSN PNO HOURS

DEPENDENT
ESSN DEPENDENT_NAME SEX BDATE RELATIONSHIP

CS 322 (ER to Relational Mapping) - Dr. Yousry Taha

You might also like