L 4
L 4
L 4
Example:
We create the relations EMPLOYEE, DEPARTMENT, and
PROJECT in the relational schema corresponding to the regular
entities in the ER diagram.
SSN, DNUMBER, and PNUMBER are the primary keys for the
relations EMPLOYEE, DEPARTMENT, and PROJECT as shown.
– For each weak entity type W in the ER schema with owner entity type E,
create a relation R and include all attributes of the weak entity as
attributes of the new relation R.
– Then, include the primary key of the owner entity as foreign key
attributes of R.
– The primary key of R is the combination of the primary key(s) of the
owner(s) and the partial key of the weak entity type W, if any.
Example:
Create the relation DEPENDENT in this step to correspond to the weak
entity type DEPENDENT. Include the primary key SSN of the EMPLOYEE
relation as a foreign key attribute of DEPENDENT (renamed to ESSN).
The primary key of the DEPENDENT relation is the combination {ESSN,
DEPENDENT_NAME} because DEPENDENT_NAME is the partial key of
DEPENDENT.
For each 1:1 relationship type identify the entities participating in the
relationship. There are two possible approaches below:
(1) Foreign Key approach:
– Choose one of the relations and include a foreign key in one relation (S) which is the primary key
of the other relation (T). It is better to choose an entity type with total participation in the
relationship in the role of S.
– Example: 1:1 relation MANAGES is mapped by choosing the participating entity type
DEPARTMENT to serve in the role of S, because its participation in the MANAGES relationship
type is total.
Example:
1:N relationship types WORKS_FOR, CONTROLS, and
SUPERVISION in the figure. For WORKS_FOR we include the
primary key DNUMBER of the DEPARTMENT relation as foreign
key in the EMPLOYEE relation and call it DNO.
– For each M:N relationship type, create a new relation S to represent the
relationship.
– Include as foreign key attributes in S the primary keys of the entities on
each side of the relationship; the combination of the two primary keys will
form the primary key of S.
– Also include any simple attributes of the M:N relationship type as attributes
of S.
Example:
The M:N relationship type WORKS_ON from the ER diagram is mapped by
creating a relation WORKS_ON in the relational database schema. The primary
keys of the PROJECT and EMPLOYEE relations are included as foreign keys in
WORKS_ON and renamed PNO and ESSN, respectively.
Attribute HOURS in WORKS_ON represents the HOURS attribute of the relation
type. The primary key of the WORKS_ON relation is the combination of the
foreign key attributes {ESSN, PNO}.
– For each multivalued attribute A, create a new relation. This relation will
include an attribute corresponding to the multi-valued attribute, plus the
primary key attribute of the relation that has the multi-valued attribute, K.
– The primary key attribute of the relation is the foreign key representing the
relationship between the entity and the multi-valued relation.
– The primary key of R is the combination of A and K.
Example:
The relation DEPT_LOCATIONS is created. The attribute DLOCATION
represents the multivalued attribute LOCATIONS of DEPARTMENT, while
DNUMBER-as foreign key-represents the primary key of the DEPARTMENT
relation. The primary key of R is the combination of {DNUMBER, DLOCATION}.
Example:
The relationship type SUPPY in the ER on the next slide. This can be mapped
to the relation SUPPLY shown in the relational schema, whose primary key is
the combination of the three foreign keys {SNAME, PARTNO, PROJNAME}
EngType
– Then create a relation for each category, which includes the attributes of
the category, and the surrogate key, which acts as the foreign key.
Example:
We can create a relation OWNER to correspond to the OWNER
category and include any attributes of the category in this relation.
The primary key of the OWNER relation is the surrogate key, which
we called OwnerId.
FIGURE 7.7
An ER schema for a SHIP_TRACKING database.