Beruflich Dokumente
Kultur Dokumente
Definitions
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.
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
For examples and detail of mapping ER and EER diagrams to relations, access
the PowerPoint Presentation, Chapter7Mapping.ppt from the course outline.