Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,

Similar presentations


Presentation on theme: " Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,"— Presentation transcript:

1

2  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

3 3 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)

4  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

5 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

6 6 (a) CUSTOMER entity type with simple attributes Figure 5-8: Mapping a regular entity (b) CUSTOMER relation

7 7 (a) CUSTOMER entity type with composite attribute Mapping a composite attribute (b) CUSTOMER relation with address detail

8 8 Figure 5-10: Mapping a multivalued attribute 1–to–many relationship between original entity and new relation (a) Multivalued attribute becomes a separate relation with foreign key (b)

9 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 10

11 11 NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity Foreign key Composite primary key

12 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

13 13 Mapping a unary 1:N relationship (a) EMPLOYEE entity with Manages relationship (b) EMPLOYEE relation with recursive foreign key

14 14 Figure 5-18: Mapping a unary M:N relationship (a) Bill-of-materials relationships (M:N) (b) ITEM and COMPONENT relations

15

16 16 Mapping the ternary relationship Remember that the primary key MUST be unique

17  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

18

19

20  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

21 Both outpatients and resident patients are cared for by a responsible physician Only resident patients are assigned to a bed

22 22 Supertype/subtype relationships

23 23 Mapping Supertype/subtype relationships to relations These are implemented as one-to-one relationships

24  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

25 All these types of vehicles have common attributes

26 So we put the shared attributes in a supertype

27  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)

28 Total specialization rule A patient must be either an outpatient or a resident patient

29

30  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

31 A simple attribute with different possible values indicating the subtype

32 A composite attribute with sub-attributes indicating “yes” or “no” to determine whether it is of each subtype


Download ppt " Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,"

Similar presentations


Ads by Google