erd chapter 3

48
Chapter 3 Chapter 3 Entity Relationship Entity Relationship (E-R) Modeling (E-R) Modeling

Upload: sonabir

Post on 26-May-2015

378 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Erd chapter 3

Chapter 3Chapter 3

Entity Relationship (E-Entity Relationship (E-R) ModelingR) Modeling

Page 2: Erd chapter 3

2

In this chapter, you will In this chapter, you will learn:learn:

What a conceptual model is and what What a conceptual model is and what its purpose isits purpose is

The difference between internal and The difference between internal and external modelsexternal models

How internal and external models How internal and external models serve the database design processserve the database design process

How relationships between entities How relationships between entities are defined and refined, and how such are defined and refined, and how such relationships are incorporated into relationships are incorporated into the database design processthe database design process

How ERD components affect database How ERD components affect database design and implementationdesign and implementation

Page 3: Erd chapter 3

3

Basic Modeling Basic Modeling ConceptsConcepts

Art and scienceArt and science Good judgment coupled with Good judgment coupled with

powerful design toolspowerful design tools ModelsModels

““Description or analogy used to Description or analogy used to visualize something that cannot be visualize something that cannot be directly observed” directly observed” Webster’s Webster’s DictionaryDictionary

Page 4: Erd chapter 3

4

Basic Modeling Basic Modeling ConceptsConcepts

Data ModelData Model Relatively simple representation of Relatively simple representation of

complex real-world data structurescomplex real-world data structures Basic tools for database designBasic tools for database design AbstractionAbstraction Good database design starts with a Good database design starts with a

good design of data model.good design of data model.

Page 5: Erd chapter 3

5

Basic Modeling Basic Modeling ConceptsConcepts

Data ModelData Model Different views of data and different Different views of data and different

concernsconcerns Communication is needed.Communication is needed. Impacts on overall management Impacts on overall management

system and policy, as well as decision system and policy, as well as decision make.make.

Blueprint, architecture, frameworkBlueprint, architecture, framework

Page 6: Erd chapter 3

6

Data Models: Degrees of Data Data Models: Degrees of Data AbstractionAbstraction

Three different models Three different models (according to the degree of (according to the degree of abstract)abstract) Conceptual model

o Global view of dataGlobal view of datao Basis for identification and description of main Basis for identification and description of main

data itemsdata items Internal model

o Representation of database as seen by DBMSRepresentation of database as seen by DBMSo Adapts conceptual model to specific DBMSAdapts conceptual model to specific DBMS

External modelo Based on internal data modelBased on internal data modelo Users’ views of data environmentUsers’ views of data environmento Provides subsets of internal viewProvides subsets of internal view

Physical modelo Lowest level of abstractionLowest level of abstractiono Describe the ways data being storedDescribe the ways data being stored

Page 7: Erd chapter 3

7

Page 8: Erd chapter 3

8

The Entity Relationship The Entity Relationship (E-R) Model(E-R) Model

Represents conceptual viewRepresents conceptual view Main ComponentsMain Components

EntitiesEntities Corresponds to entire table, not rowCorresponds to entire table, not row Represented by rectangleRepresented by rectangle

AttributesAttributes RelationshipsRelationships

Page 9: Erd chapter 3

9

What Should an Entity What Should an Entity Be?Be?

SHOULD BE:SHOULD BE: An object that will have many An object that will have many

instances in the databaseinstances in the database An object that will be composed of An object that will be composed of

multiple attributesmultiple attributes An object that we are trying to modelAn object that we are trying to model

SHOULD NOT BE:SHOULD NOT BE: A user of the database system A user of the database system An output of the database system (e.g. An output of the database system (e.g.

a report)a report)

Page 10: Erd chapter 3

10

Inappropriate entities

System userSystem user System outputSystem output

Appropriate entities

Figure 3-4

Page 11: Erd chapter 3

11

AttributesAttributes Characteristics of entitiesCharacteristics of entities Domain is set of possible valuesDomain is set of possible values Primary keys underlinedPrimary keys underlined

Figure 3.6

Page 12: Erd chapter 3

12

Page 13: Erd chapter 3

13

SimpleSimple Cannot be subdividedCannot be subdivided Age, sex, marital statusAge, sex, marital status

Composite (avoided)Composite (avoided) Can be subdivided into Can be subdivided into

additional attributesadditional attributes Address into street, city, zipAddress into street, city, zip

Single-valuedSingle-valued Can have only a single Can have only a single

valuevalue Person has one social Person has one social

security numbersecurity number

Multi-valued Multi-valued (avoid) in RDBMS(avoid) in RDBMS Can have many valuesCan have many values Person may have Person may have

several college several college degreesdegrees

How to avoid? (see How to avoid? (see next slide)next slide)

DerivedDerived Can be derived with Can be derived with

algorithm (Age can be algorithm (Age can be derived from date of derived from date of birth)birth)

Need to be storedNeed to be stored

Page 14: Erd chapter 3

14

Page 15: Erd chapter 3

15

Page 16: Erd chapter 3

16

Page 17: Erd chapter 3

17

Page 18: Erd chapter 3

18

Page 19: Erd chapter 3

19

RelationshipsRelationships Association between entitiesAssociation between entities Connected entities are called participantsConnected entities are called participants Operate in Operate in bothboth directions directions Connectivity describes relationship Connectivity describes relationship

classificationclassification 1:1, 1:M, M:N1:1, 1:M, M:N

CardinalityCardinality Expresses number of entity occurrences Expresses number of entity occurrences

associated with one occurrence of related entityassociated with one occurrence of related entity

Page 20: Erd chapter 3

20

Connectivity and Cardinality in an ERDConnectivity and Cardinality in an ERD

Figure 3.12

Page 21: Erd chapter 3

Relationship Relationship ParticipationParticipation

Page 22: Erd chapter 3

22

Relationship StrengthRelationship Strength Existence dependenceExistence dependence

Entity’s existence depends on existence Entity’s existence depends on existence of related entitiesof related entities

Existence-independent entities can exist Existence-independent entities can exist apart from related entitiesapart from related entities

Example:Example:

Page 23: Erd chapter 3

23

Relationship StrengthRelationship Strength Weak (non-identifying)Weak (non-identifying)

One entity is existence-independent on One entity is existence-independent on anotheranother

PK of related entity doesn’t contain PK PK of related entity doesn’t contain PK component of parent entitycomponent of parent entity

Strong (identifying)Strong (identifying) One entity is existence-dependent on One entity is existence-dependent on

anotheranother PK of related entity contains PK PK of related entity contains PK

component of parent entity component of parent entity

Page 24: Erd chapter 3

24

Page 25: Erd chapter 3

25

Page 26: Erd chapter 3

26

Weak EntityWeak Entity Existence-dependent on another Existence-dependent on another

entityentity Has primary key that is partially Has primary key that is partially

or totally or totally

derived from parent entityderived from parent entity

Figure 3.19

Page 27: Erd chapter 3

27

Relationship DegreeRelationship Degree Indicates number of associated entitiesIndicates number of associated entities UnaryUnary

Single entitySingle entity RecursiveRecursive Exists between occurrences of same entity setExists between occurrences of same entity set

BinaryBinary Two entities associatedTwo entities associated

TernaryTernary Three entities associatedThree entities associated

Page 28: Erd chapter 3

28

Three Types of Three Types of RelationshipsRelationships

Figure 3.21

Page 29: Erd chapter 3

29

Page 30: Erd chapter 3

30

Composite EntitiesComposite Entities

Used to ‘bridge’ between M:N Used to ‘bridge’ between M:N relationshipsrelationships

Bridge entities composed of Bridge entities composed of primary keys of each entity primary keys of each entity needing connectionneeding connection

Figure 3.30

Page 31: Erd chapter 3

31

Composite Entities Composite Entities (con’t.)(con’t.)

Figure 3.31

Page 32: Erd chapter 3

32

Entity Supertypes and Entity Supertypes and SubtypesSubtypes

Generalization hierarchy Generalization hierarchy Depicts relationships between higher-Depicts relationships between higher-

level supertype and lower-level subtype level supertype and lower-level subtype entitiesentities

Supertype has shared attributesSupertype has shared attributes Subtypes have unique attributesSubtypes have unique attributes Disjoint relationshipsDisjoint relationships

Unique subtypesUnique subtypes Non-overlappingNon-overlapping Indicated with a ‘G’Indicated with a ‘G’

Overlapping subtypes use ‘Gs’ SymbolOverlapping subtypes use ‘Gs’ Symbol

Page 33: Erd chapter 3

33

Page 34: Erd chapter 3

34

Page 35: Erd chapter 3

35

Page 36: Erd chapter 3

36

Generalization Generalization Hierarchy with Hierarchy with

Overlapping SubtypesOverlapping Subtypes

Figure 3.35

Page 37: Erd chapter 3

37

Developing an E-R Developing an E-R DiagramDiagram

Iterative ProcessIterative Process Step1: General narrative of Step1: General narrative of

organizational operations developedorganizational operations developed Step2: Basic E-R Model graphically Step2: Basic E-R Model graphically

depicted and revieweddepicted and reviewed Step3: Modifications made to incorporate Step3: Modifications made to incorporate

newly discovered E-R componentsnewly discovered E-R components Repeat process until designers and Repeat process until designers and

users agree E-R Diagram completeusers agree E-R Diagram complete

Page 38: Erd chapter 3

38

Supertype/Subtype Supertype/Subtype Relationship in an ERD Relationship in an ERD

Page 39: Erd chapter 3

39

Page 40: Erd chapter 3

40

Page 41: Erd chapter 3

41

First ERD Segment First ERD Segment Established Established

Figure 3.43

Page 42: Erd chapter 3

42

Second and Third ERD Second and Third ERD Segments Established Segments Established

Page 43: Erd chapter 3

43

Fourth and Fifth ERD Fourth and Fifth ERD Segments Established Segments Established

Page 44: Erd chapter 3

44

Sixth and Seventh ERD Sixth and Seventh ERD Segments Established Segments Established

Page 45: Erd chapter 3

45

Eighth ERD Eighth ERD Segment Established Segment Established

Page 46: Erd chapter 3

46

Ninth ERD Ninth ERD Segment Established Segment Established

Figures 3.51

Page 47: Erd chapter 3

47

Components of E-R Components of E-R ModelModel

Table 3.2

Page 48: Erd chapter 3

48

Completed ERDCompleted ERD

Figure 3.52