Presentation is loading. Please wait.

Presentation is loading. Please wait.

Part3 Database Analysis and Design Techniques Chapter 05- Entity-Relationship Modeling Lu Wei College of Software and Microelectronics Northwestern Polytechnical.

Similar presentations


Presentation on theme: "Part3 Database Analysis and Design Techniques Chapter 05- Entity-Relationship Modeling Lu Wei College of Software and Microelectronics Northwestern Polytechnical."— Presentation transcript:

1 Part3 Database Analysis and Design Techniques Chapter 05- Entity-Relationship Modeling Lu Wei College of Software and Microelectronics Northwestern Polytechnical University Database Systems

2 Lu Wei2 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

3 Lu Wei3 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

4 Lu Wei4 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.

5 Lu Wei5 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

6 Lu Wei6 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.

7 Lu Wei7 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.

8 Lu Wei8 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

9 Lu Wei9 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.

10 Lu Wei10 Entity and Entity Types Examples Physical existence Staff Property Customer Student Conceptual existence Viewing Inspection SC

11 Lu Wei11 Entity and Entity Types Diagrammatic representation of entity types –Each entity type is shown as a rectangle labeled with the name of the entity, which is normally a singular noun. –The first letter of each word in entity name is upper case. StaffBranch

12 Lu Wei12 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

13 Lu Wei13 Relationship and Relationship Types Relationship –A relationship is a meaningful association between two or more entities. Relationship Type –A set of meaningful associations among entity types. –A relationship type is a grouping of similar relationships.

14 Lu Wei14 Relationship and Relationship Types About simantic net BranchHasStaff B003 B007 SG37 SG14 SA9

15 Lu Wei15 StudentElectCourse s001 s003 c01 c02 c03

16 Lu Wei16 Relationship and Relationship Types Diagrammatic representation of relationship types StaffBranch Has

17 Lu Wei17 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.

18 Lu Wei18 Relationship and Relationship Types Diagrammatic representation of N-ary relationship types Client Registers Staff Branch Staff registers a client at a branch

19 Lu Wei19 Relationship and Relationship Types Title Group Publisher Collection

20 Lu Wei20 Relationship and Relationship Types Solicitor Arrangers Buyer Financial Institution Bid A buyer( 买主 ), advised by a solicitor( 法律顾问 ) and supported by a financial institution( 金融机构 ), places a bid( 投标 ).

21 Lu Wei21 Relationship and Relationship Types Questions –Is a ternary relationship is always equivalent and hence can be replaced with three binary relationships?

22 Lu Wei22 Relationship and Relationship Types Recursive Relationship –A relationship type where the same entity type participates more than once in different roles. Staff Supervises Supervisee Supervisor Student Supervises Supervisee Supervisor

23 Lu Wei23 Relationship and Relationship Types Two entities may be associated through more than one relationship. Role may be used. Staff Branch Has Manages Manager Branch Office Member of Staff

24 Lu Wei24 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

25 Lu Wei25 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.

26 Lu Wei26 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.

27 Lu Wei27 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.

28 Lu Wei28 Attributes Diagrammatic representation of attributes Staff staffNo{PK} name position salary /totalStaff Branch branchNo{PK} address street city postcode telNo[1..3] Has Manages

29 Lu Wei29 Attributes Attributes on Relationships Newspaper newspaperName PropertyForRent propertyNo Advertises dateAdvert cost Newspaper advertises property for rent

30 Lu Wei30 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

31 Lu Wei31 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.

32 Lu Wei32 Strong and Weak Entity Types

33 Lu Wei33 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

34 Lu Wei34 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) for each entity attribute, and constraints on entities.

35 Lu Wei35 Entity Type Schema Representation of entity type schema MemNo: 5-digits long integers DriverLic: State 2-letter abbreviation and a 10-digit integer separated by a blank Name: alphabetic string of length 30 containing blanks and hyphens Address: character string of length 50 PhoneNumber: character string of length 14

36 Lu Wei36 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

37 Lu Wei37 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. StaffBranch Has

38 Lu Wei38 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.

39 Lu Wei39 Structural Constraints In ER model, we can capture business rules using two types of multiplicity constraints, namely, cardinality ratio and participation.

40 Lu Wei40 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.

41 Lu Wei41 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

42 Lu Wei42 Structural Constraints Examples

43 Lu Wei43 Structural Constraints Staff staffNo Branch branchNo Manages 11 1.. 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)

44 Lu Wei44 Structural Constraints Examples

45 Lu Wei45 Structural Constraints Staff staffNo PropertyForRent propertyNo Oversees 0..10..*

46 Lu Wei46 Structural Constraints Examples

47 Lu Wei47 Structural Constraints Newspaper newspaperName PropertyForRent propertyNo Advertises 0..*1..*

48 Lu Wei48 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.

49 Lu Wei49 Structural Constraints Example

50 Lu Wei50 Structural Constraints StaffBranch Registers Client 1..1 0..*

51 Lu Wei51 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 relationship type with the identifying owner. –Weak entities have a total participation in the identifying owner relationship, and the identifying owner has a partial participation in the identifying owner relationship.

52 Lu Wei52 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.

53 Lu Wei53 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

54 Lu Wei54 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.

55 Lu Wei55 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.

56 Lu Wei56 Problems with ER Models An Example of a Fan Trap StaffBranchDivision HasOperates 1..1 1..* How to know which members of staff work at a particular branch

57 Lu Wei57 Problems with ER Models At which branch office does staff number SG37 work?

58 Lu Wei58 Problems with ER Models Restructuring ER model to remove Fan Trap StaffDivisionBranch HasOperates 1..*1..11..*1..1

59 Lu Wei59 Problems with ER Models SG37 works at branch B003.

60 Lu Wei60 Problems with ER Models An Example of a Chasm Trap BranchPropertyForRentStaff HasOversees 0..11..*1..10..* How to know which properties are available at each branch?

61 Lu Wei61 Problems with ER Models At which branch office is property PA14 available?

62 Lu Wei62 Problems with ER Models Restructuring ER model to remove Chasm Trap BranchPropertyForRentStaff HasOversees 0..11..*1..10..* Offers 1..11..*

63 Lu Wei63 Problems with ER Models

64 Lu Wei64 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.

65 Lu Wei65 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

66 Lu Wei66 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.

67 Lu Wei67 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.

68 Lu Wei68 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.

69 Lu Wei69 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.

70 Lu Wei70 Enhanced Entity-Relationship (EER) Modeling Example Staff Branch Has Manages Manager Branch Office Member of Staff Staff Manager Sales secretary

71 Lu Wei71 Enhanced Entity-Relationship (EER) Modeling

72 Lu Wei72 Enhanced Entity-Relationship (EER) Modeling

73 Lu Wei73 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.

74 Lu Wei74 Enhanced Entity-Relationship (EER) Modeling The relationship between members of subclass –Superclass may contain overlapping or distinct subclasses.

75 Lu Wei75 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.

76 Lu Wei76 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.

77 Lu Wei77 Enhanced Entity-Relationship (EER) Modeling Diagrammatic representation of Specialization / Generalization

78 Lu Wei78 Enhanced Entity-Relationship (EER) Modeling

79 Lu Wei79 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.

80 Lu Wei80 Enhanced Entity-Relationship (EER) Modeling

81 Lu Wei81 Enhanced Entity-Relationship (EER) Modeling

82 Lu Wei82 Enhanced Entity-Relationship (EER) Modeling

83 Lu Wei83 Enhanced Entity-Relationship (EER) Modeling

84 Lu Wei84 Enhanced Entity-Relationship (EER) Modeling Aggregation

85 Lu Wei85 Enhanced Entity-Relationship (EER) Modeling Composition

86 Lu Wei86 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.

87 Lu Wei87 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.


Download ppt "Part3 Database Analysis and Design Techniques Chapter 05- Entity-Relationship Modeling Lu Wei College of Software and Microelectronics Northwestern Polytechnical."

Similar presentations


Ads by Google