chapter 12/13 - objectives css 225 database systems...
TRANSCRIPT
CSS 225 Database Systems
Chapter 12 Entity-Relationship Modeling
and Chapter 13 Enhanced E-R Modeling
Asst. Prof. Chukiat Worasucheep
Applied Computer Science
SCL 801 #9
KMUTT
Chapter 12/13 - Objectives
• How to use Entity–Relationship (ER) modeling in database design.
• Basic concepts associated with ER model.
• Diagrammatic technique for displaying ER model using Unified Modeling
Language (UML).
• How to identify and resolve problems with ER models called connection
traps.
• How to build an ER model from a requirements specification.
• Understand Enhanced ER (EER) model is called specialization and
generalization.
2
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
3
@2012 by Chukiat Worasucheep
ER diagram of Branch user views of DreamHome
4
Concepts of the ER Model
• Entity types
• Relationship types
• Attributes
5
Entity Type
• Entity type
▫ Group of objects with same properties, identified by enterprise as having an independent existence.
• Entity occurrence
▫ Uniquely identifiable object of an entity type.
6
Examples of Entity Types
7
ER diagram of Staff and Branch entity types
8
Staff Branch
Relationship Types
• Relationship type
▫ Set of meaningful associations among entity types.
• Relationship occurrence
▫ Uniquely identifiable association, which includes one occurrence from each participating entity type.
9
Semantic net of Has relationship type
10
ER diagram of Branch Has Staff relationship
11
Relationship names
Relationship Types
• Degree of a Relationship
▫ Number of participating entity types in the relationship.
• Relationship of degree :
▫ two is binary
▫ three is ternary
▫ four is quaternary.
12
Binary relationship called POwns
13
Ternary relationship called Registers
14
Quaternary relationship called Arranges
15
Relationship Types
• Recursive Relationship
▫ Relationship type where same entity type participates more than once in different roles.
• Relationships may be given role names to indicate purpose that each participating entity type plays in a relationship.
16
Recursive relationship called Supervises with
role names
17
Entities associated through two distinct
relationships with role names
18
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
19
@2012 by Chukiat Worasucheep
Attributes
• Attribute
▫ Property of an entity or a relationship type.
• Attribute Domain
▫ Set of allowable values for one or more attributes.
20
Attribute Types: simple vs. composite
• Simple Attribute
▫ Attribute composed of a single component with an independent existence.
• Composite Attribute
▫ Attribute composed of multiple components, each with an independent existence.
21
Attribute Types: single vs multiple valued
• Single-valued Attribute
▫ Attribute that holds a single value for each occurrence of an entity type.
• Multi-valued Attribute
▫ Attribute that holds multiple values for each occurrence of an entity type.
22
Attributes
• Derived Attribute
▫ Attribute that represents a value that is derivable from value of a related attribute, or set of attributes, not necessarily in the same entity type.
23
Keys
• Candidate Key
▫ Minimal set of attributes that uniquely identifies each occurrence of an entity type.
• Primary Key
▫ Candidate key selected to uniquely identify each occurrence of an entity type. This should be clearly denoted in ERD.
• Composite Key
▫ A candidate key that consists of two or more attributes.
24
ER diagram of Staff and Branch entities and
their attributes
25
Entity Types
• Strong Entity Type
▫ Entity type that is not existence-dependent on some other entity type.
• Weak Entity Type
▫ Entity type that is existence-dependent on some other entity type.
• Note also that a relationship may also have attributes!
26
Strong entity type called Client and weak entity
type called Preference
27
Relationship called Advertises with attributes
28
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
29
@2012 by Chukiat Worasucheep
Structural Constraints
• Main type of constraint on relationships is called multiplicity.
▫ Multiplicity refers to the number (or range) of possible occurrences of an entity type that may relate to a single occurrence of an associated entity type through a particular relationship.
▫ Represents policies (called business rules) established by user or company.
30
Structural Constraints
• The most common degree for relationships is binary.
• Binary relationships are generally referred to as being:
▫ one-to-one (1:1)
▫ one-to-many (1:*)
▫ many-to-many (*:*)
31
Semantic net of Staff Manages Branch
relationship type
32
Multiplicity of Staff Manages Branch (1:1)
relationship
33
Semantic net of Staff Oversees PropertyForRent
relationship type
34
Multiplicity of Staff Oversees PropertyForRent
(1:*) relationship type
35
Semantic net of Newspaper Advertises
PropertyForRent relationship type
36
Multiplicity of Newspaper Advertises
PropertyForRent (*:*) relationship
37
Structural Constraints
• Multiplicity for Complex Relationships
▫ Number (or range) of possible occurrences of an entity type in an n-ary relationship when other (n-1) values are fixed.
38
Semantic net of ternary Registers relationship
with values for Staff and Branch entities fixed
39
Multiplicity of ternary Registers relationship
40
Summary of multiplicity constraints
41
Structural Constraints
• Multiplicity is made up of two types of restrictions on relationships: cardinality and participation. � P : C
▫ Cardinality
� Describes maximum number of possible relationship occurrences for an entity participating in a given relationship type.
▫ Participation
� Determines whether all or only some entity occurrences participate in a relationship. Basically there are two participation types:
� Mandatory (or all)
� Optional (or some)
42
Multiplicity as cardinality and participation
constraints
43
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
44
@2012 by Chukiat Worasucheep
Problems with ER Models
• Problems may arise when designing a conceptual data model called connection traps.
▫ Often due to a misinterpretation of the meaning of certain relationships.
▫ Two main types of connection traps are called fan traps and chasm traps.
45
Problems with ER Models
• Fan Trap
▫ Where a model represents a relationship between entity types, but pathway between certain entity occurrences is ambiguous.
• Chasm Trap
▫ Where a model suggests the existence of a relationship between entity types, but pathway does not exist between certain entity occurrences.
46
An Example of a Fan Trap
• It might occur when 1:m relationships fan out from a single entity.
47
Semantic Net of ER Model with Fan Trap
• At which branch office does staff number SG37 work?
48
Restructuring ER model to remove Fan Trap
49
Semantic Net of Restructured ER Model with
Fan Trap Removed
• SG37 works at branch B003.
50
An Example of a Chasm Trap
51
• It might occur where there is a relationship with partial participation, which forms part of the pathway between entities that are related.
• The partial participation of Staff and PropertyForRent in the oversees relation means that some properties cannot be associated with a branch office through a member of staff.
Semantic Net of ER Model with Chasm Trap
• At which branch office is property PA14 available?
52
ER Model restructured to remove Chasm Trap
53
• We need to add the missing relationship which is called `offers' between the Branch and the PropertyForRent entities.
• Be careful when you remove relationships which you consider to be redundant.
Semantic Net of Restructured ER Model with
Chasm Trap Removed
54
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
55
@2012 by Chukiat Worasucheep
Enhanced Entity-Relationship Model
• Since 1980s there has been an increase in emergence of new
database applications with more demanding requirements.
• Semantic modelling concepts are incorporated into the
original ER model and called the Enhanced Entity-
Relationship (EER) model.
• Examples of additional concept of EER model is called
specialization / generalization.
56
Specialization / Generalization
• Superclass
▫ An entity type that includes one or more distinct subgroupingsof its occurrences.
• Subclass
▫ A distinct subgrouping of occurrences of an entity type.
57
Specialization / Generalization
• Superclass/subclass relationship is one-to-one (1:1).
• Superclass may contain overlapping or distinct subclasses.
• Not all members of a superclass need be a member of a subclass.
58
Specialization / Generalization
• Attribute Inheritance
▫ An entity in a subclass represents same ‘real world’ object as in superclass, and may possess subclass-specific attributes, as well as those associated with the superclass.
• Specialization
▫ Process of maximizing differences between members of an entity by identifying their distinguishing characteristics.
• Generalization
▫ Process of minimizing differences between entities by identifying their common characteristics.
59
AllStaff relation holding details of all staff
60
Specialization/generalization of Staff entity
into subclasses representing job roles
61
Specialization/generalization of Staff entity
into job roles and contracts of employment
62
EER diagram with shared subclass and subclass
with its own subclass
63
Constraints on Specialization / Generalization
• Two constraints that may apply to a specialization/ generalization:
▫ Participation constraint
� Determines whether every member in superclass must participate as a member of a subclass.
� May be mandatory or optional.
▫ Disjoint constraint
� Describes relationship between members of the subclasses and indicates whether member of a superclass can be a member of one, or more than one, subclass.
� May be disjoint or nondisjoint.
64
Constraints on Specialization / Generalization
• There are four categories of constraints of specialization and generalization:
▫ mandatory and disjoint
▫ optional and disjoint
▫ mandatory and nondisjoint
▫ optional and nondisjoint.
65
mandatory optional
disjoint
nondisjoint
DreamHome worked example - Staff Superclass
with Supervisor and Manager subclasses
66
DreamHome worked example - Owner Superclass with
PrivateOwner and BusinessOwner subclasses
67
DreamHome worked example - Person superclass with
Staff, PrivateOwner, and Client subclasses
68
Contents
• Basic concepts associated with ER model
▫ Entities and relationship types
▫ Attributes and keys
• Structural constraints
• Problems with ER models
• Enhanced ER (EER) model: Specialization and Generalization.
• Exercises
69
@2012 by Chukiat Worasucheep
Exercises
• บรษิัทรถโดยสารเตา่ทองมรีถโดยสาร (Bus) หลายคัน แต่ละคันจัดไวส้ําหรับเสน้ทาง (Route) เฉพาะ แมว้่าบางเสน้ทางอาจจะมมีากกว่า 1 คัน แตล่ะเสน้ทางวิ-งผ่านเมอืง (Town) ตา่งๆ คนขับรถ (Drivers) 1 หรอือาจมากกวา่นั9นถกูจัดให ้ประจําแต่ละชว่ง (Stage) ของเสน้ทาง บางเมอืงมอีูร่ถ (Garage) สําหรับเก็บรถโดยสาร รถโดยสารแตล่ะคันมเีลขทะเบยีน (Registration number) และบรรทกุผูโ้ดยสารไดจ้ํานวนแตกต่างกันเนื-องจากมขีนาดแตกต่างกัน โดยบางคันจะมสีองชั 9น (ตามที-พบเห็นบอ่ยในอังกฤษหรอืฮอ่งกง) (Single or double-decked) แต่ละเสน้ทางจะมหีมายเลข (Route number) และมจีํานวนผูโ้ดยสารเฉลี-ยที-ใชใ้นแตล่ะวัน คนขับรถจะมหีมายเลขพนักงาน (Employee number) ชื-อ ที-อยู่ และอาจมีหมายเลขโทรศัพท์
70
@2012 by Chukiat Worasucheep