Вы находитесь на странице: 1из 17

Database Systems &Applications Lecture 8 EER to Relations (Contd..

Step 1: Mapping Regular Entities to Relations Step 2: Mapping Weak Entities Step 3: Mapping Binary Relationships 3 Step 4: Mapping Associative Entities Step 5: Mapping Unary Relationships Step 6: Mapping Ternary (and n-ary) Relationships Step 7: Mapping Super type/Sub type Relationships Step 8: Mapping of Union Types(Categories)

Associative Entities
An entityhas attributes A relationshiplinks entities together When should a relationship with attributes instead be an associative entity?
All relationships for the associative entity should be many The associative entity could have meaning independent of the other entities The associative entity preferably has a unique identifier, and should also have other attributes The associative entity may participate in other relationships other than the entities of the associated relationship Normally Ternary relationships should be converted

Transforming ER Diagrams into Relations (cont.) Step 4: Mapping Associative Entities


Identifier Not Assigned
Default primary key for the association relation is composed of the primary keys of the two entities (as in M:N relationship)

Identifier Assigned, because 1)It is natural and familiar to end-users or 2) Default identifier may not be unique
Use identifier as primary key The primary key of the two participating entity types becomes foreign key in the associative entity

Figure 5-16 Example of mapping an associative entity with an identifier

a) SHIPMENT associative entity

CUSTOMER Customer_ID Customer_name

SHIPMENT Shipment_ID Date Amount

VENDOR Vendor_ID Vendor Address

Figure 5-16 Example of mapping an associative entity with an identifier (cont.) b) Three resulting relations

Transforming EER Diagrams into Relations (cont.)

Step 5: Mapping Unary Relationships 5


One-to-ManyRecursive foreign key in the same relation Many-to-ManyTwo relations: One for the entity type One for an associative relation in which the primary key has two attributes, both taken from the primary key of the entity

Mapping a unary 1:N relationship

(a) EMPLOYEE entity with unary relationship

(b) EMPLOYEE relation with recursive foreign key

Mapping a unary M:N relationship

(a) Bill-of-materials relationships (M:N)

(b) ITEM and COMPONENT relations

Transforming EER Diagrams into Relations (cont.)


Step 6: Mapping Ternary (and n-ary) 6 Relationships
One relation for each entity and one for the associative entity Associative entity has foreign keys to each entity in the relationship Default primary key of associative entity consists of the three primary keys for the participating entity types Additional attributes may be required to from a unique primary key for the associative entity

10

Mapping a ternary relationship a) PATIENT TREATMENT Ternary relationship with associative entity

11

Mapping a ternary relationship (cont.) b) Mapping the ternary relationship PATIENT TREATMENT

Remember that the primary key MUST be unique

This is why treatment date and time are included in the composite primary key

But this makes a very cumbersome key

It would be better to create a surrogate key like Treatment#


12

Transforming EER Diagrams into Relations (cont.)


Step 7: Mapping Supertype/Subtype Relationships One relation for supertype and for each subtype Supertype attributes (including identifier and subtype discriminator) go into supertype relation Subtype attributes go into each subtype; primary key of supertype relation also becomes primary key of subtype relation One attribute of the supertype functions as the subtype discriminator

13

Supertype/subtype relationships

14

Mapping Supertype/subtype relationships to relations

These are implemented as one-to-one relationships

15

Transforming EER Diagrams into Relations (cont.)


SSN DriverLicenseNo Name BName Address BANK PERSON BAddress CName CAddress

COMPANY

Step 8: Mapping of Union Types(Categories)

OWNER M OWNS N

LienOrRegular PurchaseDate

CModel CMake CStyle VehicelId CYear

REGISTERED_VEHICLE TMake TYear

TModel Tonnage VehicleId


16

U
TRUCK

CAR

PERSON BANK COMPANY OWNER

SSN Bname CName

DriverLicenseNo Baddress Caddress

Name Address OwnerID OwnerID

OwnerID

OwnerID

REG_VEHICLE

VehicleID

LicensePlateNumber

CAR

VehicleID

Cstyle

Cmake

Cmodel

CYear

TRUCK

VehicleID

Tmake

Tmodelt

Tonnage

TYear

OWNS

OwnerID

VehicleID

PurchaseDate

LineOrRegular

Вам также может понравиться