You are on page 1of 32

Keys are special fields that serve two main

purposes:
Primary keys are unique identifiers of the relation in
question. Examples include employee numbers, social
security numbers, etc. This is how we can guarantee that all
rows are unique
Foreign keys are identifiers that enable a dependent
relation (on the many side of a relationship) to refer to its
parent relation (on the one side of the relationship)
Keys can be simple (a single field) or composite
(more than one field)
Keys usually are used as indexes to speed up the
response to user queries

2
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)

Combined, these are a composite


primary key (uniquely identifies the
order line)individually they are
foreign keys (implement M:N
relationship between order and product)

3
Domain Constraints
Allowable values for an attribute.
Entity Integrity
No primary key attribute may be null. All primary
key fields MUST have data
Action Assertions
Business rules.

4
Mapping Regular Entities to Relations
1. Simple attributes: E-R attributes map directly
onto the relation
2. Composite attributes: Use only their simple,
component attributes
3. Multivalued Attribute - Becomes a separate
relation with a foreign key taken from the
superior entity

5
Figure 5-8: Mapping a regular entity

(a) CUSTOMER
entity type with
simple
attributes

(b) CUSTOMER relation

6
Mapping a composite attribute

(a) CUSTOMER
entity type with
composite
attribute

(b) CUSTOMER relation with address detail

7
Figure 5-10: Mapping a multivalued attribute
(a)

Multivalued attribute becomes a separate relation with foreign key


(b)

1tomany relationship between original entity and new relation


8
Mapping Weak Entities
Becomes a separate relation with a
foreign key taken from the superior
entity
Primary key composed of:
Partial identifier of weak entity
Primary key of identifying relation
(strong entity)

9
10
NOTE: the domain constraint
for the foreign key should
NOT allow null value if
DEPENDENT is a weak
entity

Foreign key

Composite primary key

11
Mapping Unary Relationships
One-to-Many - Recursive foreign key in the same
relation
Many-to-Many - Two 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

12
Mapping a unary 1:N relationship

(a) EMPLOYEE entity with


Manages relationship

(b) EMPLOYEE
relation with
recursive foreign
key

13
Figure 5-18: Mapping a unary M:N relationship

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

(b) ITEM and


COMPONENT
relations

14
Mapping the ternary relationship

Remember that the


primary key MUST be
unique

16
Supertype:A sub grouping of the entities in
an entity type which has attributes that are
distinct from those in other sub groupings

Supertype: An generic entity type that has a


relationship with one or more subtypes
Relationships at the supertype level indicate
that all subtypes will participate in the
relationship
The instances of a subtype may participate in
a relationship unique to that subtype. In this
situation, the relationship is shown at the
subtype level
Both outpatients and
resident patients are
cared for by a
responsible physician

Only resident patients are


assigned to a bed
Supertype/subtype relationships

22
Mapping Supertype/subtype relationships to relations

These are implemented


as one-to-one
relationships

23
Generalization: The process of
defining a more general entity type from a set
of more specialized entity types. BOTTOM-UP
Specialization: The process of defining
one or more subtypes of the supertype, and
forming supertype/subtype relationships.
TOP-DOWN
All these types
of vehicles
have common
attributes
So we put
the shared
attributes in
a supertype
Completeness Constraints:
Whether an instance of a
supertype must also be a member
of at least one subtype
Total Specialization Rule: Yes (double
line)
Partial Specialization Rule: No (single
line)
Total specialization rule

A patient must be either


an outpatient or a
resident patient
Disjointness Constraints: Whether an
instance of a supertype may simultaneously
be a member of two (or more) subtypes
Disjoint Rule: An instance of the supertype can be
only ONE of the subtypes
Overlap Rule: An instance of the supertype could be
more than one of the subtypes
A simple attribute with
different possible values
indicating the subtype
A composite attribute
with sub-attributes
indicating yes or no
to determine whether it
is of each subtype

You might also like