141
2. Entity Relationship Modelling

2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

  • Upload
    others

  • View
    30

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

2. Entity Relationship Modelling

Page 2: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Indentifier attributes

- There is always one attribute, or a combination of attributes, whose value is unique and which we can use to identify the individual entity instance

- This is exactly the same concept as you have met in creating and normalising relations

- In our example EmployeeNo is unique and is called the identifier of the entity EMPLOYEE

- Entities have identifiers, tables have primary keys

- Identifiers can be COMPOSITE; i.e., made up of more than one attribute

Page 3: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Entities and Tables

- Theprincipledifferencebetweenanentityandatable(relation)isthatyoucanexpressarelationshipbetweenentitieswithoutusingforeignkeys.

- Thismakesiteasiertoworkwithentitiesintheearlydesignprocesswheretheveryexistenceofentitiesandtherelationshipsbetweenthemisuncertain.

Page 4: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Entitiesandattributes

ThisnotationistheoneusedinICT231,whichshowstheattributeswithintheentitysymbol

Page 5: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Entity types and entity instances

- Formally, what we draw in an ERD is the entity type (or entity set)

EMPLOYEE

- ‘Entities’ are, properly speaking, the individual instances

Fred,Ann

- However, the term ‘entity’ is so widely used for entity type that we shall continue to use it that way here, and when we need to refer to the individual instances of the entity we will call them entity instances

Page 6: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Relationships

- Entities can be associated with one another in relationships

- In the original ER model, relationships could have attributed, but this now tends not to be done

- A relationship can involve two or more entities

Page 7: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

What relationships represent

- The way in which entities are associated with each other is what represents the meaning of the data stored; how the system operates- ACUSTOMERplacesanORDER- ASTUDENTenrolsinaUNITOFFERING- AnEMPLOYEEworksinaDEPARTMENT

- Arelationshipbetweentwoentitiesisshownasalinelinkingtheentities

CUSTOMER ORDER

CUSTOMER ORDERplaces N1

Page 8: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Implementing Relationships

- The relationships we show on the ERD are eventually implemented as links between tables (primary key – foreign key), so that related data can be accessed- It’svitalthattherelationshipsaredefinedcorrectlyfortheparticularsystem,otherwiseyouwon’tbeabletogetatthedatayouneed

- It’simportanttorememberthatrelationshipsdoNOTrepresentprocess!- AnERDshowshowtheinformationisinterrelatedafter

theprocessinghashappened

Page 9: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

How many?

- More information about the way entities are related can be gained from considering how many of one entity instance are associated with how many of the other- eg.AtMurdoch,eachSCHOOLcanhavemanySTAFFmembersinit.However,eachSTAFFmemberbelongstoonlyoneSCHOOL

- Thus,therelationshipbetweenSCHOOLandSTAFFisone-to-many:

SCHOOL STAFF

Page 10: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Occurrence Diagrams

- ERdiagramsshowonlythecollectiveclassofentities(STAFF),nottheindividualoccurrencesoftheentities(Danny,Val,Tanya)

- However,youcanalsodrawoccurrencediagrams(alsocalledsemanticnetdiagramsorinstancediagrams)thatshowindividualentityinstances.

- Thesecanbeveryusefulinclarifyingexactlywhatismeantbythecardinalityofarelationship– howmanyinstancesofoneentityarerelatedtoaninstanceofanother

STAFF

S1

S2

S3

Val

Danny

Tanya

Page 11: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

Sc1

Sc2

Sc3

S1

S2

S3

STAFFSCHOOL

Page 12: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Maximum Cardinality

- The maximum cardinality of a relationship describes the maximumnumber of occurrences of one entity that are associated with a single occurrence of the other- Thisisalsoknowninsometextssimplyascardinality

Page 13: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Maximum Cardinality

Unit OfferingUnit1 Offering1

Unit2

Unit3

Offering2

Offering3

Offering4

- The occurrence diagram shows that one instance of a course can be related to zero, one or manyinstances of an offering. Thus the maximum cardinality of this relationship is many

- We can also see that one offering can be associated with one and only one unit. Thus the maximum cardinality of this relationship is one

Page 14: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Minimum Cardinality (optionality; participation)

- The minimum cardinality of a relationship describes the minimum number of occurrences of one entity that are associated with a single occurrence of the other

- Thisisalsoknowninsometextsasoptionality,ordinality,orparticipation

- Minimumcardinalityof0meansanoptionalrelationship

- Minimumcardinalityof1meansamandatoryrelationship

Page 15: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Minimum Cardinality

Unit OfferingUnit1 Offering1

Unit2

Unit3

Offering2

Offering3

Offering4

- This occurrence diagram shows that one instance of a unit can be related to zero, one or many instances of an offering. Thus the minimum cardinality of this relationship is zero (or it is OPTIONAL)

- We can also see that one offering can be associated with one and only one unit. Thus the minimum cardinality of this relationship is one (or it is MANDATORY)

Page 16: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Representing Cardinality: Crow’s Feet

Page 17: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Types of Cardinality

- The basic types of cardinality are:- One-to-one(1:1)- One-to-many(1:N)- Many-to-many(M:N)

Page 18: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

1:1 relationship

BA

A1

A2

A3

B1

B2

B3

Mandatory relationship on both sides:

Optional relationship on both sides:

BA

A1

A2

A3

B1

B2

B3

Page 19: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

1:N relationshipMandatory relationship on both sides:

Optional relationship on both sides:A1

A2

A3

B1

B2

B3

B4

BA

A1

A2

B1

B2

B3

BA

Page 20: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

M:N relationshipMandatory relationship on both sides:

Optional relationship on both sides:A1

A2

A3

B1

B2

B3

BA

BA

A1

A2

B1

B2

Page 21: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Reading an ERD

FacSSNFacSalaryFacRankFacHireDate

Faculty

OfferNoOffLocationOffTime

Offering

OfficeNoOffPhoneOffType

Office

Based on the ERD above, we can say that:

-An Office has zero or one Faculty working in it

-A member of Faculty works in one and only one Office

-A member of Faculty team teaches zero or many Offerings

-An Offering is taught by zero or many Faculty

Page 22: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw:- Anoccurrencediagram,and- Anentity-relationshipdiagram

- For the following description:- “Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Page 23: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Page 24: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydrivers duringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Page 25: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydrivers duringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 26: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 27: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 28: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 29: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 30: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 31: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 32: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 33: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anoccurrencediagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 34: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

Car1

Car2

Car3

Drv1

Drv2

Drv3

Page 35: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR

Page 36: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydrivers duringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER

Page 37: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER

Page 38: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER<

Page 39: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER<

Page 40: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER<0

Page 41: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER<0

Page 42: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER> 0<

Page 43: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER> 0<

Page 44: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER> 0<|

Page 45: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example Anentity-relationshipdiagram“Acarmaybedrivenbymanydriversduringtheweek,orbynone.Adrivermaydrivemanycars,andalwaysdrivesatleastone”

CAR DRIVER> 0<|

Mandatory

Optional

Page 46: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

Page 47: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM

Page 48: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER

Page 49: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER

MANAGER

Page 50: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveral players,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

Page 51: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<|

MANAGER

Page 52: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

Page 53: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

Page 54: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

0

Page 55: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

0

0

Page 56: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

0

0||

Page 57: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Draw an ERD for the following description. Explain any assumptions you need to make where there is insufficient information.- “Acricketteamhasseveralplayers,butaplayerplaysononlyoneteam.Ateamhasonemanager”

TEAM PLAYER<

MANAGER

|

|

0

0||

0

Page 58: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Many-to-many relationships

- M:N relationships are sometimes called non-specific relationships- Theycanalwaysberesolvedintopairsof1:N

relationships,andthisshouldbedoneduringmodelling,beforetheERDismappedtorelationaltables- Can’timplementaM:Nrelationshipdirectlyas

tables- Resolvingtherelationshipgivesmoreprecisionto

themodel,andmayrevealmoreattributes/relationshipsthanwerepreviouslyapparent

Page 59: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Many-to-many relationships

- M:N relationships are sometimes called non-specific relationships- Theycanalwaysberesolvedintopairsof1:N

relationships,andthisshouldbedoneduringmodelling,beforetheERDismappedtorelationaltables- Can’timplementaM:Nrelationshipdirectlyas

tables- Resolvingtherelationshipgivesmoreprecisionto

themodel,andmayrevealmoreattributes/relationshipsthanwerepreviouslyapparent

Page 60: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 61: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 62: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 63: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 64: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 65: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 66: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Resolving an M:N relationship using an associative entity

- Create another entity to represent the combination of the participating entities:

STUDENT OFFERINGENROLMENT

STUDENT OFFERING

- This is known as an associative entity (also called an intersection or association entity)

- The primary key of the associative entity is the combination of the primary keys from the related entities

Page 67: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

M:N Relationships with attributes

- InaM:Nrelationshiptheremaybeattributesassociatedwiththecombination ofbothentities- E.g.,agradeisassociatedwithastudentenrolledin

anofferingofaunit

Page 68: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Improved precision

StdSSNStdName

StudentOfferNoOffLocationOffTime

Offering

EnrGradeEnrollment

AttDatePresent

Attendance

- ReplacingtheM:Nwithtworelationshipsandanassociativeentitycanimproveprecisionofthemodel:- Theassociationmayhaveattributes(e.g.,Gradeforthe

Student:UnitOfferingrelationship)- Theassociationmayneedtoberelatedtootherentities

Page 69: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

AuthNoAuthName

AuthorISBNTitle

Book

AuthOrder

b) Writes relationship

Writes

- How would this be drawn using an associative entity?

Page 70: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

Writes relationship:

Author Book

> 0<|AuthNo

AuthNameISBNTitleWrites

AuthOrder

Page 71: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

Writes relationship:

Author Book

> 0<|AuthNo

AuthNameISBNTitle

BookAuthorAuthNoISBNOrder

Page 72: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

Writes relationship:

Author Book

> 0<|AuthNo

AuthNameISBNTitle

BookAuthorAuthNoISBNOrder

Page 73: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

Writes relationship:

Author Book

>0< |AuthNo

AuthNameISBNTitle

BookAuthorAuthNoISBNOrder

Page 74: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example…

Writes relationship:

Author Book

>0< |AuthNo

AuthNameISBNTitle

BookAuthorAuthNoISBNOrder

||||

Page 75: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Other types of relationships

- Other types of relationships you may meet include:- Morethanonerelationshipbetweenthesameentities

- Recursiverelationships- Multi-wayrelationships

Page 76: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

More than one relationship between the same entities

- This may be necessary to represent the complete meaning of the system:- PERSONworksonPROJECT

PERSONleadsPROJECT- STUDENTborrowsLIBRARYBOOK- STUDENTrecallsLIBRARYBOOK

- Model with separate relationships, as they may have different cardinalities and optionalities

PERSON PROJECT

leads

works on

Page 77: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Recursive Relationships

- Occurs when an entity has a relationship with itself- Alsoknownasunaryorself-referencingrelationships- Examples:

- Amemberoffacultymaysuperviseothermembersoffacultyand,inturnbesupervisedbyothermembersoffaculty

- Aunitmaybeaprerequisiteforotherunits

Page 78: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Representing recursive relationships

- The ERD shows a relationship line drawn from one side of the entity to the other, using the usual cardinality and optionality symbols

FacSSNFacName

Faculty

a) manager-subordinate b) unit prerequisites

UnitNoUnitTitle

Unit

Page 79: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Multi Way (M-Way) Relationships

- M-Way Relationships- Relationshipbetweenmorethantwoentities

- Binary– twoentities(theusual)- Ternary – threeentities- Quarternary– fourentities- N-ary – manyentities

- Generallyrepresentedasaseriesofbinaryrelationshipswithanassociative entitytorepresenttherelationship

Page 80: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

M-Way Relationships

PartNoPartName

PartSuppNoSuppName

Supplier

Associative entity type

ProjNoProjName

Project

Uses

Page 81: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Weak Entities

BldgIDBldgNameBldgLocation

Building

RoomNoRoomCapacity

Room

Identification Dependency Symbols:• Solid relationship line for identifying

relationships• Diagonal lines in the corners denote

weak entities.

- Weakentitiesarethosewhoseinstancescannotexistwithoutaninstanceofanotherentity- itisexistence-dependent ontheowner

entity- Intheexamplebelow,aroomcannothaveanexistence

withoutthebuildingitisin

Page 82: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Weak entities in ERD’s

- Have a different symbol for the entity

- Always have a mandatory relationship with their owner entity

- Usually have a composite primary key made up in part of the primary key of the owner entity (identification dependence)

LINE-ITEMORDER STAFF NEXT OF KINN1

has

Page 83: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Weak entities in ERD’s

- The Common Pattern (e.g. Invoice)

RonCo InvoiceInvoice#

DateCustomer

01 131132 Ring $25.1002 23511 Washer $19.0003 631345 Screw $05.5004 931465 Hose $24.2505 331590 Pipe $15.10

Total $84.75GST $19.01

Invoice Total $103.76

INVOICE

ITEM

LINEITEM<

<

LINEITEM

Page 84: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Examples of weak entities

- Typically used to model collections of things within the owner entity- AnOrderanditsLine-Items– alineitemdoesn’tmakesenseexceptinthecontextofanorder

- Phonecallswithinanitemisedtelephonebill- Faultreportingonanitemofmachinery- Legswithinanairlineroute

- Modelling history - attribute variation over time- Personandtheirweightsondifferentdates

- Also used where the entity has no meaning within the database without its owner entity- StaffandtheirNext-of-Kin

Page 85: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

What else should I do?- In the real world, there are variations, so:

- Chenallowsveryprecisemodellingofattributes,butisverybulkytodraw

- Crow’sfeetareconciseandsimple,butyouneedtodocumenttheattributesseparatelyasyougo

- Fully-attributedERDscanbedifficulttoread,butprovideaveryclearmappingtothelogicaldesignandimplementation

- When drawing your own ERDs, use any one that you are comfortable with, so long as:- Youdon’tmakeupyourown!- YouusethesameconventionallthewaythroughtheERD- Youincludealegendwiththediagramtomakeitquiteclearwhatthesymbolsrepresent

- You should be able to READ any of the notations

Page 86: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

How to construct an ERD

- It is an iterative process!- Identifyentities,attributes,relationships

- Inawrittenorverbaldescription,nounsareoftenentities,verbsgivecluesastorelationships

- Othersourcesareforms,reports,existingdatabases

- SketchtheERD- NormalisetheERD- Removemultivaluedattributes,resolveM:Nrelationships

- Checkfor‘syntax’errors- Checkthatthediagramiscomplete- Dofurtherchecksforcorrectness,includingverifyingassumptionswithclient

Page 87: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Another method for constructing an ERD- Discover entities

- Entitiesmustbeaboutonlyonething- Construct context data model

- Showentitiesandrelationshipcardinality- Identify the keys of each entity

- Showprimarykey- Create fully attributed data model

- addattributes.- Attributesmustrelateonlytothatentity

- Improve data model using normalization

- Thisisgenerallyausefulapproachtofollow,althoughmanynotationsdon’tsupporttheinclusionofattributeswithintheERDitself– however,theyshouldalwaysbedocumented

Page 88: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Using Entity-Relationship modelling in Requirements Analysis

- The ultimate aim of drawing an ERD is to create a representation or model of the system.- However,it’salsoausefulwayofexploringideas

aswellasdocumentingthem- findingoutwhatyouknowanddon’tknowaboutthesystem

- Wheneveryoudraftadiagram,noteonit:- Whatyouaresureabout- Whatyouareunsureabout- Whatquestionsyouneedtoasktoclarifythepartsyou

aren’tsureabout

Page 89: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Exercise: Kids’n’Vans

Draw a conceptual ERD to represent the Kids’ n’Vans data requirements:• “Kids’n’Vans retails minivans for a number of

manufacturers. • Each manufacturer offers several models of its minivan

(e.g., SE, LE, GT). • Each model comes with a standard set of equipment (e.g.,

the Acme SE comes with wheels, seats, and an engine)

• Minivans can have a variety of additional equipment or accessories (radio, air conditioning, automatic transmission, airbag, etc.), but not all accessories are available for all minivans (e.g., not all manufacturers offer a driver’s side airbag).

• Some sets of accessories are sold as packages (e.g., the luxury package might include stereo, six speakers, cocktail bar, and twin overhead fluffy dice).

Page 90: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

• “Kids’n’Vans retails minivans for a number of manufacturers.

• Each manufacturer offers several models of its minivan (e.g., SE, LE, GT).

• Each model comes with a standard set of equipment (e.g., the Acme SE comes with wheels, seats, and an engine)

• Minivans can have a variety of additional equipment or accessories (radio, air conditioning, automatic transmission, airbag, etc.), but not all accessories are available for all minivans (e.g., not all manufacturers offer a driver’s side airbag).

• Some sets of accessories are sold as packages (e.g., the luxury package might include stereo, six speakers, cocktail bar, and twin overhead fluffy dice).

Page 91: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

• “Kids’n’Vans retails minivans for a number of manufacturers.

• Each manufacturer offers several models of its minivan (e.g., SE, LE, GT).

• Each model comes with a standard set of equipment (e.g., the Acme SE comes with wheels, seats, and an engine)

• Minivans can have a variety of additional equipment or accessories (radio, air conditioning, automatic transmission, airbag, etc.), but not all accessories are available for all minivans (e.g., not all manufacturers offer a driver’s side airbag).

• Some sets of accessories are sold as packages (e.g., the luxury package might include stereo, six speakers, cocktail bar, and twin overhead fluffy dice).

Page 92: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

• “Kids’n’Vans retails minivans for a number of manufacturers.

• Each manufacturer offers several models of its minivan (e.g., SE, LE, GT).

• Each model comes with a standard set of equipment (e.g., the Acme SE comes with wheels, seats, and an engine)

• Minivans can have a variety of additional equipment or accessories (radio, air conditioning, automatic transmission, airbag, etc.), but not all accessories are available for all minivans (e.g., not all manufacturers offer a driver’s side airbag).

• Some sets of accessories are sold as packages (e.g., the luxury package might include stereo, six speakers, cocktail bar, and twin overhead fluffy dice).

MINIVAN

MFG

MODEL STANDARDEQUIPMENT EQUIPMENT

OPTIONALEQUIPMENT

EQUIPMENTPACKAGES

Page 93: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

• “Kids’n’Vans retails minivans for a number of manufacturers.

• Each manufacturer offers several models of its minivan (e.g., SE, LE, GT).

• Each model comes with a standard set of equipment (e.g., the Acme SE comes with wheels, seats, and an engine)

• Minivans can have a variety of additional equipment or accessories (radio, air conditioning, automatic transmission, airbag, etc.), but not all accessories are available for all minivans (e.g., not all manufacturers offer a driver’s side airbag).

• Some sets of accessories are sold as packages (e.g., the luxury package might include stereo, six speakers, cocktail bar, and twin overhead fluffy dice).

MINIVAN <

MFG

MODEL STANDARDEQUIPMENT EQUIPMENT

OPTIONALEQUIPMENT

EQUIPMENTPACKAGES

| >

>

<

<

Page 94: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Extended Entity-Relationship modelling

Generalisation and specialisation (subtyping)

Page 95: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Enhanced Entity-Relationship Model

- Basic concepts of ER modeling are often not sufficient to represent requirements of some more complex applications.

- Semantic concepts were incorporated into the original ER model and called the Enhanced Entity-Relationship (EER) model.

- The most useful additional data modelling concept of the Enhanced ER (EER) model is called specialisation/generalisation, and is based on classification

Page 96: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Classification

- The process of ‘grouping’ objects based on some similarities:- Biologicaltaxonomies,suchasFamily/Genus/Species

- AdministrativeclassificationssuchasStudents/Faculty/AdministrativeStaff

- Classification is what allows us to model inheritance/generalisation for our database- Canmodelentitiesthatsharecommoncharacteristicsbutwhichalsohavedifferences

Page 97: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Generalisation

EmployeeEmpNoEmpNameEmpHireDate

...

SalaryEmpEmpSalary

HourlyEmpEmpRate

generalization hierarchysymbol

supertype

subtypes

- Collectionofentitiesarrangedinahierarchicalstructurebasedonsimilaritiesbetweenattributes- Eachsubtyperepresentsasubsetofthe

parententity.

Page 98: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Inheritance

- Anentityinasubtyperepresentssame‘realworld’objectasinsupertype,andmaypossesssubtypespecificattributes,aswellasthoseassociatedwiththesupertype- Subtypesinheritattributesofsupertypes(directand

indirect)- eg.theSalaryEmpsubtypesinheritstheEmpName

andEmpHiredateattributes

EmployeeEmpNoEmpNameEmpHireDate

...

SalaryEmpEmpSalary

HourlyEmpEmpRate

generalization hierarchysymbol

supertype

subtypes

Page 99: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

AllStaff relationholdingdetailsofallstaff

Page 100: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Specialization/generalization of Staff entity into subtypes representing job roles

Page 101: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

ConstraintsonSpecialisation/Generalisation

- A supertype may contain overlapping or distinct subtypes. - Notallmembersofasupertypeneedbeamemberofasubtype

- Twoconstraintsthatmayapplytoaspecialization/generalizationare:- participation constraints

- disjointconstraints.

Page 102: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Participation/Disjoint Constraints

Participation constraint- Determineswhethereverymemberinsupertypemustparticipateasamember

ofasubtype.- Maybemandatoryoroptional:

- mandatory:everyinstanceofasupertypemustalsobeaninstanceinthesubtypes

- optional: theremaybeinstancesinthesupertypethatarenotinthesubtype

Disjointconstraint- Describestherelationshipbetweenmembersofthesubtypesandindicates

whethermemberofasupertypecanbeamemberofone,ormorethanone,subtype.

- Maybedisjoint(noentityinstanceincommon– or)ornondisjoint(overlapping– and)

Page 103: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

SecuritySymbolSecNameLastClose

StockOutSharesIssuedShares

BondRate

FaceValue

{Mandatory, Or}

Disjointness Constraint

Participation Constraint

- Thedisjoint constraintbelowmeansthatifasecurityisastockitcannotalsobeabond

- Theparticipation constraintmeansthateverysecuritymustbeeitherastockorabond

Page 104: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Specialization/generalization of Staff entity into subtypes representing job roles

Page 105: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Specialisation / Generalisation example ctd.

Page 106: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

3. How to check your ERD

Page 107: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

How do you know if you’ve got it right?- Even though it’s a diagram, you can

check an ERD for errors in the same sort of way as you do programs- Syntaxerrors

- Errorsinthe‘grammar’ofthetechnique– usingthenotationincorrectly

- Logicerrors- Errorsthatmeanthesystemisn’trepresentedcorrectly– businessrulesare

notrepresented

- Run-timeerrors- Errorsthatmeanthesystemwon’tperformcorrectlyinpracticeandovertime

Page 108: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Errors in the diagramming notation: Check -

- Entities named correctly?- Musthavesingularnames- Musthaveuniquenames- Mustrepresenttypes,notinstances

- Primary keys indicated?(ifyouareusinganotationthatshowsattributes)

- Relationships have complete cardinality/optionality indicated at both ends?

- Relationships are only between entities – not between other relationships?

Page 109: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Errors that mean the system isn’t represented correctly according to the business rules: Check -

- Are your entities really entities?

- Are your attributes really attributes?

- Are your relationships are really relationships?

- Are the correct entities related?

- Is the cardinality of relationships correct?

- Try to get into the habit of recognising typical patterns of entities and relationships- Theseincludebothtrapstoavoid,andtypicalbusiness

usagepatterns– thisislargelyamatterofexperience

Page 110: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?1. Modelling the system as an entity- Recognised by the entity being named for the system, and problems in

working out what relationships it has- Often arises because of a literal reading of a description: “Dream Home

Real Estate has several branches…”- It is wrong because an entity must have the potential for many

individual instances, and ‘the system’ is only one instance

BRANCHDREAM HOME REAL ESTATE

- Ask yourself: are there any other real estate agencies to be modelled in this system? If so, keep it as an entity (called AGENCY), if not, remove it

Page 111: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?2. Modelling reports as entities

- Clue: an entity called ‘Weekly Report’ or similar

- Again, follows from a literal reading of the problem description- Thisiswrong becausereportsareanoutputofthedatabase- the

resultofqueryingonthedatabasecontents(oftenfrommanyindividualtables)– ontheDFD,wouldbeshownasadataflowtoanexternalagent

PROPERTYPROPERTY AVAILABLE

REPORT

To fix: Remove the entity, and check that all the information you require for the report can be found from the data model (more of this in a later topic)

Page 112: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?3. Modelling attributes as entities

- If you find you can’t define any attributes of an entity, consider whether it is really an entity in itself, or just an attribute of the related entity

- Make it an attribute if:- Itonlytakesonevaluefortheentityinstance,andthat

valueislikelytobespecifictotheparticularinstance- Consider keeping it as a separate entity if:- Itcanbemultivaluedfortheentity(sincemultivalued

attributesnotpermittedinRM)- Thevaluesitcantakewouldbereusablebyotherinstancesofthe

relatedentity

Page 113: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example

- Student has date of birth- Wouldnotmodelasanentityasthereisonlyeveronevalueforthestudent

DATE OF BIRTHSTUDENT

The fact that many students could share a DOB is not likely to be relevant - date of birth is not of interest in its own right in this system

Page 114: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Another example…

- Student has Address- WouldpossiblymodelStudentAddressasaweakentityif

multipleaddressesweretobestored,- egsemesteraddress,mailingaddress,permanentaddress

STUDENT-ADDRESSSTUDENT ?

Page 115: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?3. Modelling attributes as entities -Example

- Car has Colour- PotentiallyaseparateentityCOLOURifmultiplecolours possiblefor

thatmodel,andusingastandardcolour setthatcouldapplytomanymodels

- Inthisexample,Colour wouldbeofinterestinitsownright(andyouwouldprobablyfindextraattributes,specifictocarmanufacture,suchascodeorbatchnumber)

CAR-COLOURCAR COLOUR

Page 116: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?4. Entities that aren’t related to any other entities

- This is usually a sign that the entity doesn’t belong in this system- Checkfortheothererrorsfirst– maybeyouhaverepresentedthesystemitself,orareport

- Occasionallyyouwouldwantastandaloneentitytoprovideasetoflookupvalues,butthissituationisveryunlikelyinanydatamodelyouwillbeaskedtodrawinICT218!

Page 117: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your entities really entities?5. Entities that are the same thing, but different state

- A ‘Prospect’ eventually becomes a ‘Student’ – should this be modelled as:- Tworelatedentities?- AnentityStudent,withattribute‘State’whichcantakethevalueProspective?

- Ageneralisation(supertype)entityStudent,withsubtypesEnrolledandProspective?

Page 118: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your attributes really attributes?1. Attributes that should be entities

- A complex or multivalued attribute often becomes a related entity instead when the entity is fully normalised

ATHLETE

AthleteNameAthleteAddress

….….

Sponsor (name, address, city)

SPONSOR

SponsorNameSponsorAddressSponsorCity

…..…..

ATHLETE

AthleteNameAthleteAddress

….….

(Primary keys and foreign keys not shown)

Page 119: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your attributes really attributes?2. Mistaking values for attributes

Thiscaneasilybedonewhenusingprintedformsasthebasisforthedatamodel– canbetemptingtousethemtooliterally:

Paymentmethod:PaypalCreditCash

X

- Separate attributes Paypal, Credit, Cash, each with Yes/No values??

- If another payment method is accepted, need to redo database design – so not a good solution

- Attribute PaymentMethod, with possible values Paypal, Credit, Cash

- Extendible to another payment method simply by adding a new value to the list of valid ones for that field – more flexible solution

Page 120: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are your relationships really relationships?

- Check that you haven’t modelled process instead of relationship- Inthedatamodel,itdoesn’tnecessarilymatterhowsomethingcomesabout,justwhattheresultis- eg.SecretaryupdatesPropertytable– shouldthisindicatearelationshipbetweenSecretaryandPropertyentities??- Ifweneedtokeeptrackofwhoupdateswhat,forauditing

purposes,thenYES- OtherwiseNO

Page 121: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Are the correct entities related?

- Getting the correct entities, but relating them incorrectly, is the cause of some typical ‘traps’ which we shall consider shortly- Generally,thesetrapsarisefromrepresentingindirectrelationshipsratherthanthemostdirect

Page 122: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Is the cardinality of relationships correct?

- Check using occurrence diagrams to be sure you understand what the cardinality represents, and make sure this matches the business rules of the system- Rememberhowtoreadcardinality:itreferstoinstancesoftheentity,nottheset- ie,‘howmanyinstancesofentityBarerelatedto

ONEinstanceofentityA?’- Makesurethecardinalityiscorrectfortheentirelifetimeofthedatabase

Page 123: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Checking an ERD using Occurrence Diagrams

Unit OfferingUnit1 Offering1

Unit2

Unit3

Offering2

Offering3

Offering4

(What is the corresponding ERD?)

Page 124: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Get into the habit of recognising typical patterns of entities and relationships

- These include:- Trapstoavoid(nextsection)- TypicalERconstructions

- ExpandingaM:Nrelationshiptotwo1:N- Useofaweakentitytorepresenthistory

- Typicalbusinessusagepatterns- This is largely a matter of experience

and practice

Page 125: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Errors that mean the system won’t function correctly1. Forgetting about the timescale of the database

- A typical error is to forget about time so that you end up with an ERD which will work for a single occasion, but not repeated use- Askyourself:doesthisERDmodelthedatabaseforthelengthoftimeitwilllast?- Usuallythesolutionistoaddanotherentityto

representmultipleoccasionsofsomething(seeexampleonnextslide)

Page 126: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Example: thinking of the time dimension

ENROLSSTUDENT UNIT

ENROLSSTUDENT UNITUNIT-OFFERING

- OK for this semester… but what happens if you fail ICT218 and need to come back next semester?

- This is better, can now have multiple enrolments in a ‘unit-offering’- Still need to ask: would this distinguish different years

adequately for the system?

Page 127: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Errors that mean the system won’t function correctly2. Being inflexible

- Not really an error, but more like poor practice – you should always design a system to be flexible- Prepareformultipleoccurrencesofthingsthatareonlysupposedto

happenonce- Beabletohandlealargersetofpossiblevaluesthantheonesgiven- Allowforthepossibilityofdifferentbehaviourbyusingsubtypes- Keepconceptsasdistinctaspossiblethroughnormalisation

- it’seasytocombineentitiesusingqueries,butimpossibletosplitupsomethingthatisawhole

Page 128: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Classic ‘Traps’ – errors to avoid

Page 129: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Fan Trap

FACULTYLECTURER SCHOOL

Which School does Lecturer 3 work in??

L1

L2

L3

D1

D2

D3

S1

S2

S3

Page 130: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Fan Trap

- There is potential for a Fan Trap whenever there is a many-to-one then one-to-manyrelationship- Example- AtMurdoch,eachisinaparticularFaculty,andaFacultyhasmanySchools.AFacultyalsohasmanylecturers

- Wecan’tfindoutfromthisdiagramwhatSchoolwhichlecturerworksin- yetweknow(fromourknowledgeofMurdoch)thatlecturersareassociatedwithparticularSchools- Problemarosebecausewedrewaderivedrelationship

(FacultyhasLecturer)insteadofthedirectone,SchoolhasLecturer

- Solution:Redrawusingthedirectrelationship

Page 131: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Fan Trap: Solution

Now we can see that Lecturer 3 works in School 3

SCHOOLFACULTY LECTURER

L1

L2

L3

D1

D2

D3

S1

S2

S3

Page 132: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Fan Trap – another example

OFFICEEMPLOYEE PHONE

- Isthisafantrap??- Supposewehaveanopenplanoffice,withno

connectionbetweenphoneandemployee- anyemployeecanuseanyphoneintheoffice

- Thentherewouldbenoproblemwiththisrepresentation

Page 133: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Checking for the Fan Trap

- Not every N:1 1:N pattern is a fan trap – but many are, so look out for it- Thefantrapalsoapplies(potentially)ifthereisamany-to-many relationshipfollowedbyaone-to-manyoramanytomany- (becausetheM:Nrelationshipcanberesolvedintotwo

1:Nrelationshipswithanewassociativeor'intersection'entity)

Page 134: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Chasm Trap

Which branch manages Property P3?

P1

P2

P3

B1

B2

B3

S1

S2

S3

STAFFBRANCH PROPERTY

Page 135: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Chasm Trap- The Chasm Trap arises when there are optional

relationships in a pathway between related entities, so that for some entity instances it is impossible to get at the relationship- Intheexample,notallpropertiesatabranchareassignedtostaff– soitisimpossibletotellwhichbranchthesepropertiesareregisteredat

- Solution:addinthedirectrelationship

Page 136: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Chasm Trap

Now we can see that Property 3 is managed by Branch 2

P1

P2

P3

B1

B2

B3

S1

S2

S3

STAFFBRANCH PROPERTY

B1

B2

B3

Page 137: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Checking for the Chasm Trap

- Check any pathway of related entities that includes optional relationships for potential chasm traps - Again,thepresenceofoptionalrelationshipsmaynotindicateaproblem,butitisalwaysworthchecking

- Solutionsmayincludeaddinganotherrelationship,orrestructuringtheexistingones

Page 138: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Incomplete circular relationships

HABITAT

SPECIES LOCATION

We have many-to-many relationships everywhere… but can we find out if a particular species is found in a particular habitat and location?

Page 139: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Incomplete circular relationships

- Incomplete circular relationships can arise when you need to represent a combination of more than two entities- Often a clue is a combination of several many-to-

many relationships, which don’t solve the problem even when expanded

- Solution is to create another entity, to deal with the combination directly

Page 140: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

Incomplete circular relationships: Solution

HABITAT

SPECIES LOCATIONOCCURRENCE

CreateacentralentityOccurrencetorepresentthecombinationofSpecies,HabitatandLocation

Page 141: 2. Entity Relationship Modellingsecure.com.sg/courses/ICT285/S03_T05_Slides_Conceptual.pdf · Entity types and entity instances-Formally, what we draw in an ERD is the entity type(or

A final word on entity relationship diagrams….

- ERDs are a valuable modelling tool for database design:- Specifythemeaningofasystem- Explainthedesigner’sunderstandingofthesystemtotheclient

- Basisforlogicaldatabasedesign(nexttopic)- Try to develop a consistent way of drawing ERDs- Makeuseoflegendswhereverrequired(includingassignmentsandexams!)toassistothersinunderstandingyourdiagrams

- Learnfromyourmistakesandlearnfromyoursuccesses– thisisthewayyouwillbuildupexpertise