Sie sind auf Seite 1von 2

Mapping ER/EER Diagrams to Relations

Definitions

Primary Key – A primary key is a field (or combination of fields, called a


composite key), which uniquely identifies a row or entity.

Candidate Key – a key, although not selected as a primary key, can also be
used to uniquely identify a row or entity.

Foreign Key - a field in one relation, which refers to a field in another. Foreign
keys are used in relational schema to represent a relationship between two
relations/entities. A foreign key in one relation refers to the primary key field of
the related relation/entity.

Examples of a Foreign Key

Suppose we have two tables, Customer and Purchase. These entities are
related by the Purchases relationship.

Purchase
Customer s Purchase

If we were to show the relations (tables) that are created based on the above ER
diagram, it would look like the schema shown below.

Customer
CustID CustName DOB CreditNumber

Purchase
PurchaseID ProductID ProductName Date PurchasingCustID

In the example above, the PurchasingCustID field in the Purchase relation is the
foreign key, and it refers to the primary key of the Customer relation. The foreign
key represents the relationship between customer and purchase, or in other
words, indicates the customer who purchased the given product.

Relational Schema
 The example above is an example of a relational schema. The relational
schema shows the relations (tables) and the attributes of the relations, and
the keys of each relation, including primary keys and foreign keys.
 Often when creating a relational schema, you indicate primary keys using an
underline.
 Foreign keys are sometimes represented using an arrow from the foreign key
field in the relation, to the primary key field in the relation to which it refers.

Customer
CustID CustName DOB CreditNumber

Purchase
PurchaseID ProductID ProductName Date PurchasingCustID

Steps to Mapping ER/EER Diagrams to Relational Schema:


1. Mapping Strong Entity Types
2. Mapping Weak Entity Types
3. Mapping of 1:1 Relationships
4. Mapping of 1:N Relationships
5. Mapping of M:N Relationships
6. Mapping of Multi-valued Attributes
7. Mapping of n-ary Relationships (Relationships whose degree is >1
8. Mapping of Specialization/Generalization
9. Mapping of Unions (Categories)

For examples and detail of mapping ER and EER diagrams to relations, access
the PowerPoint Presentation, Chapter7Mapping.ppt from the course outline.

Das könnte Ihnen auch gefallen