59
Chapter 4: Chapter 4: The Enhanced ER Model and The Enhanced ER Model and Business Rules Business Rules 1 Modern Database Management 8th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden By: Aatif Kamal Dated: March 2008

Chapter 4: The Enhanced ER Model and Business Rules

  • Upload
    apu

  • View
    68

  • Download
    4

Embed Size (px)

DESCRIPTION

Modern Database Management 8th Edition Jeffrey A. Hoffer , Mary B. Prescott, Fred R. McFadden. Chapter 4: The Enhanced ER Model and Business Rules. By: Aatif Kamal Dated: March 2008. Objectives. Definition of terms Use of supertype /subtype relationships - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter  4: The Enhanced ER Model and Business Rules

Chapter 4:Chapter 4:

The Enhanced ER Model and The Enhanced ER Model and Business RulesBusiness Rules

1

Modern Database Management8th Edition

Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden

By: Aatif KamalDated: March 2008

Page 2: Chapter  4: The Enhanced ER Model and Business Rules

2

ObjectivesObjectives Definition of termsDefinition of terms Use of supertype/subtype relationshipsUse of supertype/subtype relationships Use of generalization and specialization techniquesUse of generalization and specialization techniques Specification of completeness and disjointness Specification of completeness and disjointness

constraintsconstraints Develop supertype/subtype hierarchies for realistic Develop supertype/subtype hierarchies for realistic

business situationsbusiness situations Develop entity clustersDevelop entity clusters Explain universal data modelExplain universal data model Name categories of business rulesName categories of business rules Define operational constraints graphically and in Define operational constraints graphically and in

EnglishEnglish

Page 3: Chapter  4: The Enhanced ER Model and Business Rules

Enhanced-ER (EER) Model Concepts Includes all modeling concepts of basic ER Additional concepts:

subclasses/superclasses, specialization/generalization, categories, attribute inheritance

The resulting model is called the enhanced-ER or Extended ER (E2R or EER) model

It is used to model applications more completely and accurately if needed

It includes some object-oriented concepts, such as inheritance

Page 4: Chapter  4: The Enhanced ER Model and Business Rules

4

Supertypes and SubtypesSupertypes and Subtypes Subtype:Subtype: A subgrouping of the entities in an A subgrouping of the entities in an

entity type that has attributes distinct from entity type that has attributes distinct from those in other subgroupingsthose in other subgroupings

Supertype:Supertype: A generic entity type that has a A generic entity type that has a relationship with one or more subtypesrelationship with one or more subtypes

Attribute Inheritance:Attribute Inheritance: Subtype entities inherit values of all Subtype entities inherit values of all

attributes of the supertypeattributes of the supertype An instance of a subtype is also an An instance of a subtype is also an

instance of the supertypeinstance of the supertype

Page 5: Chapter  4: The Enhanced ER Model and Business Rules

Subclasses and Superclasses (1) An entity type may have additional

meaningful sub-groupings of its entities Example:

EMPLOYEE may be further grouped into SECRETARY, ENGINEER, MANAGER, TECHNICIAN, SALARIED_EMPLOYEE, HOURLY_EMPLOYEE,…

Each of these groupings is a subset of EMPLOYEE entities

Each is called a subclass of EMPLOYEE EMPLOYEE is the superclass for each of these

subclasses These are called superclass/subclass

relationships. Example: EMPLOYEE/SECRETARY,

EMPLOYEE/TECHNICIAN

Page 6: Chapter  4: The Enhanced ER Model and Business Rules

Instances of a specialization.

Page 7: Chapter  4: The Enhanced ER Model and Business Rules

Subclasses and Superclasses (2) These are also called IS-A IS-A relationshipsrelationships

(SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, …). Note: An entity that is member of a subclass

represents the same real-world entity as some member of the superclass The Subclass member is the same entity in a distinct

specific role An entity cannot exist in the database merely by

being a member of a subclass; it must also be a member of the superclass

A member of the superclass can be optionally included as a member of any number of its subclasses

Example: A salaried employee who is also an engineer belongs to the two subclasses ENGINEER and SALARIED_EMPLOYEE It is not necessary that every entity in a superclass

be a member of some subclass

Page 8: Chapter  4: The Enhanced ER Model and Business Rules

Attribute Inheritance in Superclass / Subclass Relationships An entity that is member of a subclass

inherits all attributes of the entity as a member of the superclass

It also inherits all relationships

Page 9: Chapter  4: The Enhanced ER Model and Business Rules

9

Figure 4-1 Basic notation for supertype/subtype notation

a) EER notation

Page 10: Chapter  4: The Enhanced ER Model and Business Rules

10

Different modeling tools may have different notation for the same modeling constructs

b) Microsoft

Visio Notation

Figure 4-1 Basic notation for supertype/subtype notation (cont.)

Page 11: Chapter  4: The Enhanced ER Model and Business Rules

11

Figure 4-2 Employee supertype with three subtypes

All employee subtypes will have emp nbr, name, address, and date-hired

Each employee subtype will also have its own attributes

Page 12: Chapter  4: The Enhanced ER Model and Business Rules

12

Relationships and SubtypesRelationships and Subtypes Relationships at the Relationships at the supertypesupertype level indicate level indicate

that all subtypes will participate in the that all subtypes will participate in the relationshiprelationship

The instances of a The instances of a subtypesubtype may participate in may participate in a relationship unique to that subtype. In this a relationship unique to that subtype. In this situation, the relationship is shown at the situation, the relationship is shown at the subtype levelsubtype level

Page 13: Chapter  4: The Enhanced ER Model and Business Rules

13

Figure 4-3 Supertype/subtype relationships in a hospital

Both outpatients and resident patients are cared for by a responsible physician

Only resident patients are assigned to a bed

Page 14: Chapter  4: The Enhanced ER Model and Business Rules

14

Generalization and SpecializationGeneralization and Specialization

Generalization:Generalization: The process of The process of defining a more general entity type from a set defining a more general entity type from a set of more specialized entity types. BOTTOM-UPof more specialized entity types. BOTTOM-UP

Specialization:Specialization: The process of defining The process of defining one or more subtypes of the supertype and one or more subtypes of the supertype and forming supertype/subtype relationships. TOP-forming supertype/subtype relationships. TOP-DOWNDOWN

Page 15: Chapter  4: The Enhanced ER Model and Business Rules

15

Figure 4-4 Example of generalization

a) Three entity types: CAR, TRUCK, and MOTORCYCLE

All these types of vehicles have common attributes

Page 16: Chapter  4: The Enhanced ER Model and Business Rules

16

Figure 4-4 Example of generalization (cont.)

So we put the shared attributes in a supertype

Note: no subtype for motorcycle, since it has no unique attributes

b) Generalization to VEHICLE supertype

Page 17: Chapter  4: The Enhanced ER Model and Business Rules

Generalization.

(a)Two entity types, CAR and TRUCK.

(b) Generalizing CAR and TRUCK into the superclass VEHICLE.

Page 18: Chapter  4: The Enhanced ER Model and Business Rules

Specialization Is the process of defining a set of subclasses of a Is the process of defining a set of subclasses of a

superclasssuperclass The set of subclasses is based upon some distinguishing

characteristics of the entities in the superclass Example: {SECRETARY, ENGINEER, TECHNICIAN} is a

specialization of EMPLOYEE based upon job type. May have several specializations of the same superclass

Example: Another specialization of EMPLOYEE based in method of pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}. Superclass/subclass relationships and specialization can

be diagrammatically represented in EER diagrams Attributes of a subclass are called specific attributes. For

example, TypingSpeed of SECRETARY The subclass can participate in specific relationship

types. For example, BELONGS_TO of HOURLY_EMPLOYEE

Page 19: Chapter  4: The Enhanced ER Model and Business Rules

Example of a Specialization

Page 20: Chapter  4: The Enhanced ER Model and Business Rules

20

Figure 4-5 Example of specialization

a) Entity type PART

Only applies to manufactured parts

Applies only to purchased parts

Page 21: Chapter  4: The Enhanced ER Model and Business Rules

21

b) Specialization to MANUFACTURED PART and PURCHASED PART

Note: multivalued attribute was replaced by an associative entity relationship to another entity

Created 2 subtypes

Figure 4-5 Example of specialization (cont.)

Page 22: Chapter  4: The Enhanced ER Model and Business Rules

Notation for Specialization

Employee

Secretary

Technician

Engineer

d

WorkFor

Department

Belongs To

ProfessionalOrganization

Page 23: Chapter  4: The Enhanced ER Model and Business Rules

Constraints on Specialization & Generalization

Several specializations can be defined on an entity type.

Entities may belong to subclasses in each of the specializations.

The specialization may also consist of a single subclass, such as the manager specialization, in this case we don’t use the circle notation.

Types of SpecializationsTypes of Specializations Predicate-defined or Condition-defined specializationPredicate-defined or Condition-defined specialization Attribute-defined specializationAttribute-defined specialization User-defined specializationUser-defined specialization

Page 24: Chapter  4: The Enhanced ER Model and Business Rules

Types of Specializations: Types of Specializations: Predicate-definedPredicate-defined

If we can determine exactly those entities that will become members of each subclass by a conditionby a condition, the subclasses are called predicate-definedpredicate-defined (or (or condition-defined) subclassescondition-defined) subclasses

Example: Income > 0Income > 0

The condition is called the defining predicate of the sub class.

The condition is a constraint specifying exactly those entities of the Employee entity type whose attribute value for Job Type is Secretary belong to the subclass.

Predicate defined subclasses are displayed by writing the predicate condition next to the line that connects the subclass to the specialization circle

Page 25: Chapter  4: The Enhanced ER Model and Business Rules

Types of Specializations: Types of Specializations: Attribute-definedAttribute-defined If all subclasses in a specialization have

membership condition on same attribute of the superclass, specialization is called an attribute definedattribute defined-specialization-specialization Attribute is called the defining attribute of the

specialization Example: JobType is the defining attribute of the

specialization {SECRETARY, TECHNICIAN, ENGINEER} of EMPLOYEE

Attribute-defined specializations are displayed by placing the defining attribute name next to the arc from the circle to the super class.

Page 26: Chapter  4: The Enhanced ER Model and Business Rules

EER diagram notation for an attribute-defined specialization on JobType.

Page 27: Chapter  4: The Enhanced ER Model and Business Rules

Types of Specializations: Types of Specializations: User-definedUser-defined If no condition determines membership, the

subclass is called user-defined Membership in a subclass is determined by the

database users by applying an operation to add an entity to the subclass

Membership in the subclass is specified individually for each entity in the superclass by the user

Page 28: Chapter  4: The Enhanced ER Model and Business Rules

Constraints on Specialization and Generalization Two other conditions apply to a

specialization/generalization: Disjointness Constraint:

Specifies that the subclasses of the specialization must be disjointeddisjointed (an entity can be a member of at most at most one of the subclasses of the specialization)

Specified by ‘dd’’ in EER diagram If not disjointed, overlapoverlap; that is the same

entity may be a member of more than more than one subclass of the specialization

Specified by ‘oo’’ in EER diagram

Page 29: Chapter  4: The Enhanced ER Model and Business Rules

EER diagram notation for an overlapping (nondisjoint) specialization.

O

Page 30: Chapter  4: The Enhanced ER Model and Business Rules

Constraints on Specialization and Generalization Completeness Constraint:

TotalTotal specifies that every entity in the superclass must be must be a member of some subclass in the specialization/ generalization

Shown in EER diagrams by a double line Partial Partial allows an entity not to (may or not to (may or

may not) may not) belong to any of the subclasses

Shown in EER diagrams by a single line

Page 31: Chapter  4: The Enhanced ER Model and Business Rules

Constraints on Specialization and Generalization Hence, we have four types of specialization /

generalization constraints:

Disjoint, total Disjoint, partial Overlapping, total Overlapping, partial

Note: Generalization usually is total because the superclass is derived from the subclasses.

Disjointness vs. CompletenessDisjointness vs. Completeness Disjoint constraints and completeness constraints are

independent. The following possible constraints on specializations are

possible:

Page 32: Chapter  4: The Enhanced ER Model and Business Rules

Disjointness vs. Completeness

Disjoint, totalDisjoint, total

Disjoint, partialDisjoint, partialEmployee

d

Secretary Analyst Engineer

Department

d

AcademicAdministrative

Page 33: Chapter  4: The Enhanced ER Model and Business Rules

Disjointness vs. Completeness

Overlapping, totalOverlapping, totalPart

o

Manufactured

Purchased

Overlapping, partialOverlapping, partialMovie

o

Children Comedy Drama

Page 34: Chapter  4: The Enhanced ER Model and Business Rules

34

Constraints in Supertype/ Completeness Constraint (ONCE AGAIN)

Completeness ConstraintsCompleteness Constraints: : Whether Whether an instance of a supertype an instance of a supertype mustmust also be a also be a member of at least one subtypemember of at least one subtype Total Specialization Rule: Yes (double line)Total Specialization Rule: Yes (double line) Partial Specialization Rule: No (single line)Partial Specialization Rule: No (single line)

Page 35: Chapter  4: The Enhanced ER Model and Business Rules

35

Figure 4-6 Examples of completeness constraints

a) Total specialization rule

A patient must be either an outpatient or a resident patient

Page 36: Chapter  4: The Enhanced ER Model and Business Rules

36

b) Partial specialization rule

A vehicle could be a car, a truck, or neither

Figure 4-6 Examples of completeness constraints (cont.)

Page 37: Chapter  4: The Enhanced ER Model and Business Rules

37

Constraints in Supertype/ Disjointness Constraints in Supertype/ Disjointness constraint constraint (ONCE AGAIN)(ONCE AGAIN)

Disjointness ConstraintsDisjointness Constraints: : Whether an instance of a supertype may Whether an instance of a supertype may simultaneouslysimultaneously be a member of two (or more) be a member of two (or more) subtypessubtypes Disjoint Rule: Disjoint Rule: An instance of the supertype can An instance of the supertype can

be only ONE of the subtypesbe only ONE of the subtypes Overlap Rule: Overlap Rule: An instance of the supertype could An instance of the supertype could

be more than one of the subtypesbe more than one of the subtypes

Page 38: Chapter  4: The Enhanced ER Model and Business Rules

38

a) Disjoint rule

Figure 4-7 Examples of disjointness constraints

A patient can either be outpatient or resident, but not both

Page 39: Chapter  4: The Enhanced ER Model and Business Rules

39

b) Overlap rule

A part may be both purchased and manufactured

Figure 4-7 Examples of disjointness constraints (cont.)

Page 40: Chapter  4: The Enhanced ER Model and Business Rules

Insertion & Deletion rules Deleting an entity from a superclass implies that it

is automatically deleted from all the subclasses to which it belongs.

Inserting an entity in a superclass means that the entity is mandatorily inserted in all predicate-defined (attribute defined) subclasses for which the entity satisfies the defining predicate.

Inserting an entity in a superclass of total specialization implies that the entity is mandatorily inserted in at least one of the subclasses of the specialization.

Number of other rules can be inferred for insertions & deletion can be derived from various types of specializations.

Page 41: Chapter  4: The Enhanced ER Model and Business Rules

Example of __________ SpecializationDisjoint Disjoint

PartialPartial

Page 42: Chapter  4: The Enhanced ER Model and Business Rules

Specialization / Generalization Hierarchies, Lattices and Shared Subclasses (01) A subclass may itself have further subclasses

specified on it Forms a hierarchyhierarchy or a lattice lattice HierarchyHierarchy has a constraint that every

subclass has only one superclass (called single inheritancesingle inheritance)

Lattice,Lattice, a subclass can be subclass of more than one superclass (called multiple multiple inheritanceinheritance)

In a lattice or hierarchy, a subclass inherits attributes not only of its direct superclass, but also of all its predecessor superclasses

A subclass with more than one superclass is called a shared subclassshared subclass

Page 43: Chapter  4: The Enhanced ER Model and Business Rules

Specialization / Generalization Hierarchies, Lattices and Shared Subclasses (02) Can have specialization hierarchies or

lattices, or generalization hierarchies or lattices

In specialization, start with an entity type and then define subclasses of the entity type by successive specialization (top down conceptual refinement process)

In generalization, start with many entity types and generalize those that have common properties (bottom up conceptual synthesis process)

In practice, the combination of two processes is employed

Page 44: Chapter  4: The Enhanced ER Model and Business Rules

Specialization/Generalization Specialization/Generalization Lattices and Hierarchies (Example)Lattices and Hierarchies (Example)

In a lattice, when a superclass inherits attributes from more than one superclass, and some attributes are some attributes are inherited more than once via different pathsinherited more than once via different paths (i.e. Engineer, Manager and Salaried Employee all inherit from Employee, that are then inherited by Engineering Manager.

In this situationIn this situation, , the attributes are included only once in the attributes are included only once in the subclassthe subclass

Employee

Secretary

Technician

Engineer Manager

Salaried_Emp

Hourly Emp

Engineering Manager

d d

Page 45: Chapter  4: The Enhanced ER Model and Business Rules

45

Figure 4-8 Introducing a subtype discriminator (disjoint rule)

A simple attribute with different possible values indicating the subtype

attribute definedattribute defined--specializationspecialization

Page 46: Chapter  4: The Enhanced ER Model and Business Rules

46

Figure 4-9 Subtype discriminator (overlap rule)A composite attribute with sub-attributes indicating “yes” or “no” to determine whether it is of each subtype

Predicate-Predicate-defineddefined

Page 47: Chapter  4: The Enhanced ER Model and Business Rules

47

Figure 4-10 Example of supertype/subtype hierarchy

Page 48: Chapter  4: The Enhanced ER Model and Business Rules

Specialization / Generalization Lattice Example (UNIVERSITY)

Page 49: Chapter  4: The Enhanced ER Model and Business Rules

Categories (UNION TYPES) All of the superclass/subclass relationships

we have seen thus far have a single superclass

A shared subclass is subclass in more than one distinct superclass/subclass relationships, where each relationships has a single superclass (multiple inheritance)

In some cases, need to model a single superclass/subclass relationship with more than one superclass

Superclasses represent different entity types Such a subclass is called a category or

UNION TYPEUNION TYPE

Page 50: Chapter  4: The Enhanced ER Model and Business Rules

Example of categories (UNION TYPES)

Database for vehicle registration, vehicle owner can be a person, a bank (holding a lien on a vehicle) or a company. Category (subclass)

OWNEROWNER is a subset of the union of the three superclasses COMPANYCOMPANY, BANKBANK, and PERSONPERSON

A category member must exist in at least one of its superclasses

Note: The difference from shared subclass, which is subset of the intersection of its superclasses (shared subclass member must exist in all of its superclasses).

Page 51: Chapter  4: The Enhanced ER Model and Business Rules

Formal Definitions of EER Model (1) Class C:Class C: A set of entities; could be entity type,

subclass, superclass, category. Subclass S:Subclass S: A class whose entities must always be

subset of the entities in another class, called the superclass C of the superclass/subclass (or IS-A) relationship C/S:

S ⊆ CS ⊆ C Specialization Z:Specialization Z: Z = {S1, S2,…, Sn} a set of

subclasses with same superclass G; hence, G/Si a superclass relationship for i = 1, …., n. G is called a generalization of the subclasses {S1, S2,…, Sn} Z is totalZ is total if we always have:

S1 ∪ S2 ∪ … ∪ Sn = G;Otherwise, Z is partialZ is partial.

Z is disjointZ is disjoint if we always have:Si ∩ S2 empty-set for i ≠ j;

Otherwise, Z is overlappingZ is overlapping.

Page 52: Chapter  4: The Enhanced ER Model and Business Rules

Formal Definitions of EER Model (2) Subclass S of C is predicate defined if predicate p on attributes of

C is used to specify membership in S; that is, S = C[p], where C[p] is the set of entities in C that satisfy p

A subclass not defined by a predicate is called user-defined Attribute-defined specialization: if a predicate A = cA = cii (where A is

an attribute of G and ci is a constant value from the domain of A) is used to specify membership in each subclass Si in Z Note:Note: If ci ≠ cj for i ≠ j, and A is single-valued, then the attribute-

defined specialization will be disjoint. Category or UNION type T

A class that is a subset of the union of n defining superclasses D1, D2,…Dn, where n>1:

T ⊆ (D1 ∪ D2 ∪ … ∪ Dn) A predicate pi on the attributes of T. If a predicate pi on the attributes of Di can specify entities of Di that

are members of T. If a predicate is specified on every Di then : T = (D1[p1] ∪ D2[p2] ∪…∪

Dn[pn] Note: The definition of relationship type should have 'entity type'

replaced with 'class'.

Page 53: Chapter  4: The Enhanced ER Model and Business Rules

A specialization lattice with multiple inheritance for a UNIVERSITY database.

Page 54: Chapter  4: The Enhanced ER Model and Business Rules

An EER conceptual schema for a UNIVERSITY database.

Page 55: Chapter  4: The Enhanced ER Model and Business Rules

55

Entity ClustersEntity Clusters EER diagrams are difficult to read when there EER diagrams are difficult to read when there

are too many entities and relationshipsare too many entities and relationships Solution: Group entities and relationships into Solution: Group entities and relationships into

entity clustersentity clusters Entity clusterEntity cluster: Set of one or more entity : Set of one or more entity

types and associated relationships grouped types and associated relationships grouped into a single abstract entity typeinto a single abstract entity type

Page 56: Chapter  4: The Enhanced ER Model and Business Rules

56

Figure 4-13a Possible entity clusters for Pine Valley Furniture in Microsoft Visio

Related groups of entities could become clusters

Page 57: Chapter  4: The Enhanced ER Model and Business Rules

57

Figure 4-13a Possible entity clusters for Pine Valley Furniture in Microsoft Visio

Related groups of entities could become clusters

Page 58: Chapter  4: The Enhanced ER Model and Business Rules

58

Figure 4-13b EER diagram of PVF entity clusters

More readable, isn’t it?

Page 59: Chapter  4: The Enhanced ER Model and Business Rules

59

Figure 4-14 Manufacturing entity cluster

Detail for a single cluster