Upload
maisie-dickson
View
31
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Part3 Database Analysis and Design Techniques Chapter 05- Entity-Relationship Modeling. Lu Wei College of Software and Microelectronics Northwestern Polytechnical University. Database Systems. Outline. Introduction Entity and Entity Types Relationship and Relationship Types Attributes - PowerPoint PPT Presentation
Citation preview
Part3 Database Analysis and Design TechniquesChapter 05-Entity-Relationship Modeling
Lu WeiCollege of Software and MicroelectronicsNorthwestern Polytechnical University
Database Systems
Lu Wei 2
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 3
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 4
Introduction
• Once the requirements collection and analysis stage of the database application lifecycle is complete and we have documented the requirements for the database application, we are ready to begin the database design stage.
• One of the most difficult aspects of database design is the fact that designers, programmers,
and end-users trend to view data and its use in different ways.
Lu Wei 5
Introduction
• Unless we gain a common understanding that reflects how the enterprise operates, the design we produce will fail to meet the users’ requirements.
• To ensure that we get a precise understanding of the nature of the data and how it is used by the enterprise, a model is needed for communication
Lu Wei 6
Introduction
• Requirements for the model– Non-technical– Free of ambiguities ( 无二义 )
• The Entity-Relationship (ER) model is one such example.
• ER modeling is a top-down approach to database design.
• ER modeling is an important technique for any database designer to master.
Lu Wei 7
Introduction
• The diagrammatic notations for representing ER model– Unified Modeling Language (UML)– The Crow’s Feet Notation– The Chen Notation
• The ER model provides a semi-formal notation that allows designers to create a high-level conceptual schema.
Lu Wei 8
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 9
Entity and Entity Types
• Entity – An entity is an object in the real world that is uniquely
identifiable and has independent existence. • Entity Type
– Entities having the same properties are grouped together to form an entity type .
– Note that the convention is to use singular form for an entity type name.
– Can be objects with a physical (or real) existence or conceptual existence.
Lu Wei 10
Entity and Entity Types
• Examples
Physical existenceStaffPropertyCustomerStudent Conceptual existenceViewingInspectionSC
Lu Wei 11
Entity and Entity Types
• Diagrammatic representation of entity types– Each entity type is shown as a rectangle labeled with t
he name of the entity, which is normally a singular noun.
– The first letter of each word in entity name is upper case.
Staff Branch
Lu Wei 12
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 13
Relationship and Relationship Types
• Relationship – A relationship is a meaningful association between tw
o or more entities. • Relationship Type
– A set of meaningful associations among entity types.– A relationship type is a grouping of similar relationship
s.
Lu Wei 14
Relationship and Relationship Types
• About simantic net
Branch Has Staff
B003
B007
SG37
SG14
SA9
Lu Wei 15
Student Elect Course
s001
s003
c01
c02
c03
Lu Wei 16
Relationship and Relationship Types
• Diagrammatic representation of relationship types
Staff BranchHas
Lu Wei 17
Relationship and Relationship Types
• Degree of Relationship Type– The number of participating entity types in a
relationship.• The majority of the relationships in a database
are binary.
Lu Wei 18
Relationship and Relationship Types
• Diagrammatic representation of N-ary relationship types
Client
Registers
Staff
Branch
Staff registers a client at a branch
Lu Wei 19
Relationship and Relationship Types
Title
Group
Publisher
Collection
Lu Wei 20
Relationship and Relationship Types
Solicitor
ArrangersBuyer
Financial Institutio
nBid
A buyer( 买主 ), advised by a solicitor( 法律顾问 ) and supported by a financial institution( 金融机构 ), places a bid( 投标 ).
Lu Wei 21
Relationship and Relationship Types
• Questions – Is a ternary relationship is always equivalent and
hence can be replaced with three binary relationships?
Lu Wei 22
Relationship and Relationship Types
• Recursive Relationship– A relationship type where the same entity type particip
ates more than once in different roles.
Staff
Supervises
Supervisee
Supervisor Stude
nt
Supervises
Supervisee
Supervisor
Lu Wei 23
Relationship and Relationship Types
• Two entities may be associated through more than one relationship. Role may be used.
Staff BranchHas
ManagesManager Branch Office
Branch OfficeMember of Staff
Lu Wei 24
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 25
Attributes
• Attribute – A property of an entity or a relationship type.
• Attribute domain– The set of allowable values for one or more attributes.
• Simple (atomic) Attribute– Attribute composed of a single component with an
independent existence.• Composite Attribute
– Attribute composed of multiple components, each with an independent existence.
Lu Wei 26
Attributes
• 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.
• 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.
Lu Wei 27
Attributes
• 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.
• Composite Key– A candidate key that consists of two or more
attributes.
Lu Wei 28
Attributes
• Diagrammatic representation of attributes
Staff
staffNo{PK}namepositionsalary/totalStaff
Branch
branchNo{PK}address street city postcodetelNo[1..3]
Has
Manages
Lu Wei 29
Attributes
• Attributes on Relationships
Newspaper
newspaperNamePropertyForRentpropertyNo
Advertises
dateAdvertcost
Newspaper advertises property for rent
Lu Wei 30
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 31
Strong and Weak 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.
Lu Wei 32
Strong and Weak Entity Types
Lu Wei 33
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 34
Entity Type Schema
• Entity Type Schema– An entity type schema specifies the common structure
shared by individual entities of that type. – Include a type name, name, and domain (value set) fo
r each entity attribute, and constraints on entities.
Lu Wei 35
Entity Type Schema
• Representation of entity type schema
MemNo: 5-digits long integersDriverLic: State 2-letter abbreviation and a 10-digit integer separated by a blankName: alphabetic string of length 30 containing blanks and hyphensAddress: character string of length 50PhoneNumber: character string of length 14
Lu Wei 36
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 37
Structural Constraints
• There should be constraints placed on entity types that participate in a relationship.
• Do each branch must have staff?• The constraints on relationships are used to
express restrictions on relationships that exist in the real world.
Staff BranchHas
Lu Wei 38
Structural Constraints
• Main type of constraint on relationships is called multiplicity ( 多样性 ).
• Multiplicity– 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.
Lu Wei 39
Structural Constraints
• In ER model, we can capture business rules using two types of multiplicity constraints, namely, cardinality ratio and participation.
Lu Wei 40
Structural Constraints
• Cardinality ratio ( 基数约束 )– 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.
Lu Wei 41
Structural Constraints
• The most common degree for relationships is binary.
• For cardinality constraint, binary relationships are generally referred to as being:– one-to-one (1:1)– one-to-many (1:*)– many-to-many (*:*)
• There are two types of participation constraints– Mandatory participation– Optional participation
Lu Wei 42
Structural Constraints
• Examples
Lu Wei 43
Structural Constraints
Staff
staffNoBranch
branchNoManages1 11.. 0..
One branch is managed by one member of staff
One member of staff manages one branch
Cardinality
Participation
All branches are managed (mandatory)
Not all staff manage branches (optional)
Lu Wei 44
Structural Constraints
• Examples
Lu Wei 45
Structural Constraints
Staff
staffNoPropertyForRentpropertyNo
Oversees0..1 0..*
Lu Wei 46
Structural Constraints
• Examples
Lu Wei 47
Structural Constraints
Newspaper
newspaperNamePropertyForRentpropertyNo
Advertises0..* 1..*
Lu Wei 48
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.
Lu Wei 49
Structural Constraints
• Example
Lu Wei 50
Structural Constraints
Staff BranchRegisters
Client
1..1 1..1
0..*
Lu Wei 51
Structural Constraints
• Discuss about the multiplicity constraints between strong entity type and weak entity type.– A weak entity type must participate in a one-to-many r
elationship type with the identifying owner.– Weak entities have a total participation in the identifyi
ng owner relationship, and the identifying owner has a partial participation in the identifying owner relationship.
– Weak entities have a total participation in the identifying owner relationship, and the identifying owner has a partial participation in the identifying owner relationship.
Lu Wei 52
Structural Constraints
• Notation: – A total participation constraint does not imply that the
corresponding participating entity type is a weak entity.– The requirements of the system determine the choice
of strong entities versus weak entities versus multi-valued attributes.
Lu Wei 53
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 54
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.
Lu Wei 55
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.
Lu Wei 56
Problems with ER Models
• An Example of a Fan Trap
Staff BranchDivisionHas Operate
s1..11..11..* 1..*
How to know which members of staff work at a particular branch
Lu Wei 57
Problems with ER Models
At which branch office does staff number SG37 work?
Lu Wei 58
Problems with ER Models
• Restructuring ER model to remove Fan Trap
Staff DivisionBranchHas Operate
s1..*1..11..* 1..1
Lu Wei 59
Problems with ER Models
SG37 works at branch B003.
Lu Wei 60
Problems with ER Models
• An Example of a Chasm Trap
Branch PropertyForRentStaffHas Oversee
s0..11..*1..1 0..*
How to know which properties are available at each branch?
Lu Wei 61
Problems with ER Models
At which branch office is property PA14 available?
Lu Wei 62
Problems with ER Models
• Restructuring ER model to remove Chasm Trap
Branch PropertyForRentStaffHas Oversee
s0..11..*1..1 0..*
Offers
1..1 1..*
Lu Wei 63
Problems with ER Models
Lu Wei 64
Problems with ER Models
• Discuss – When a fan trap may exist?– When a chasm trap may occur?
• A fan trap may exist where two or more 1:* relationships fan out from the same entity.
• A chasm trap may occur where there are one or more relationships with a minimum multiplicity of zero (that is optional participation) forming part of the pathway between related entities.
Lu Wei 65
Outline
• Introduction• Entity and Entity Types• Relationship and Relationship Types• Attributes• Strong and Weak Entity Types• Entity Type Schema• Structural Constraints• Problems with ER Models• Enhanced Entity-Relationship Modeling
Lu Wei 66
Enhanced Entity-Relationship (EER) Modeling
• Since 1980s there has been an increase in emergence of new database applications with more demanding requirements.
• Basic concepts of ER modeling are not sufficient to represent requirements of newer, more complex applications.
• Response is development of additional ‘semantic’ modeling concepts.
Lu Wei 67
Enhanced Entity-Relationship (EER) Modeling
• Semantic 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.
Lu Wei 68
Enhanced Entity-Relationship (EER) Modeling
• Specialization / Generalization – Superclass
• An entity type that includes one or more distinct subgroupings of its occurrences.
– Subclass• A distinct subgrouping of occurrences of an entity type.
Lu Wei 69
Enhanced Entity-Relationship (EER) Modeling
• Specialization/generalization was introduced for two additional reasons:– To help in identifying the attributes and relationships specific to some entities, thereby enhancing the understanding of the application and adding more semantic clarity to the design.
– To avoid specifying attributes to an entity not applicable to it. This eliminates the need for a great number of NULL values.
Lu Wei 70
Enhanced Entity-Relationship (EER) Modeling
• Example
Staff BranchHas
ManagesManager Branch Office
Branch OfficeMember of Staff
Staff
Manager
Sales
secretary
Lu Wei 71
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 72
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 73
Enhanced Entity-Relationship (EER) Modeling
• The relationship between supclasses and its subclasses– 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.
– Superclass/subclass relationship is one-to-one (1:1).– Not all members of a superclass need be a member
of a subclass.
Lu Wei 74
Enhanced Entity-Relationship (EER) Modeling
• The relationship between members of subclass– Superclass may contain overlapping or distinct
subclasses.
Lu Wei 75
Enhanced Entity-Relationship (EER) Modeling
• Constraints on 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.
Lu Wei 76
Enhanced Entity-Relationship (EER) Modeling
• There are four categories of constraints of specialization and generalization:– mandatory and disjoint– optional and disjoint– mandatory and nondisjoint– optional and nondisjoint.
Lu Wei 77
Enhanced Entity-Relationship (EER) Modeling
• Diagrammatic representation of Specialization / Generalization
Lu Wei 78
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 79
Enhanced Entity-Relationship (EER) Modeling
• 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.
Lu Wei 80
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 81
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 82
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 83
Enhanced Entity-Relationship (EER) Modeling
Lu Wei 84
Enhanced Entity-Relationship (EER) Modeling
• Aggregation
Lu Wei 85
Enhanced Entity-Relationship (EER) Modeling
• Composition
Lu Wei 86
Summary
• In this chapter you should have learned:– How to use Entity-Relationship (ER) modeling in a
database design– The basic concepts associated with the Entity-
Relationship (ER) model– A diagrammatic technique for displaying an ER model
using the Unified Modeling Language (UML) or the Crow’s Feet Notation.
Lu Wei 87
Summary
– How to identify and resolve some problems with ER models
– How to build an ER model from a requirements specification
– The useful additional data modeling concepts of Enhanced ER (EER) model.