35
1 . Ching, Ph.D. • MIS • California State University, Sacramento Week 9 Week 9 October 24 October 24 Modeling with ERD Modeling with ERD

1 R. Ching, Ph.D. MIS California State University, Sacramento Week 9 October 24 Modeling with ERDModeling…

Embed Size (px)

DESCRIPTION

3 R. Ching, Ph.D. MIS California State University, Sacramento ERD Notation Music_categories music_category_code {PK} music_category_title CDs stock_number {PK} CD_titleartistmusic_category_coderecord_label_code Entity type Primary key Attributes Relationship name Classify  * Relationship type Degree of the Relationship: Binary Multiplicity (constraint)

Citation preview

1

R. Ching, Ph.D. • MIS • California State University, Sacramento

Week 9Week 9October 24October 24

• Modeling with ERDModeling with ERD

2

R. Ching, Ph.D. • MIS • California State University, Sacramento

Entity Relationship (ER) ModelEntity Relationship (ER) Model(applies to relational data model)(applies to relational data model)

• High-level conceptual model High-level conceptual model – Describes the structure of the database, and the Describes the structure of the database, and the

associated retrieval and update transactions on the associated retrieval and update transactions on the databasedatabase

– Composed of Composed of • Entity types Entity types • Relationship typesRelationship types• AttributesAttributes

3

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation

Music_categoriesMusic_categoriesmusic_category_code {PK}music_category_code {PK}music_category_titlemusic_category_title

CDsCDs

stock_number {PK}stock_number {PK}CD_titleCD_titleartistartistmusic_category_code music_category_code record_label_coderecord_label_code

Entity typeEntity typePrimary keyPrimary key

AttributesAttributes

Relationship nameRelationship name

ClassifyClassify

1..11..1 0..*0..*

Relationship typeRelationship type

Degree of the Relationship: BinaryDegree of the Relationship: Binary

Multiplicity (constraint)Multiplicity (constraint)

4

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD NotationAlternativelyAlternatively

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Entity typeEntity typePrimary key (underscored)Primary key (underscored)

AttributesAttributes

Relationship typeRelationship typeRelationship nameRelationship name

ManyMany(crows feet)(crows feet)

CardinalityCardinality

ZeroZero(circle)(circle)

MinimumMinimum(inside)(inside)MaximumMaximum

(outside)(outside)

5

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERDERD

• Entity type – A group of objects with the same properties, Entity type – A group of objects with the same properties, which are identified by the enterprise as having an which are identified by the enterprise as having an independent existenceindependent existence

• Relationship type – A set of meaningful associations Relationship type – A set of meaningful associations among entity typesamong entity types

• Attributes – A property of an entity or a relationship typeAttributes – A property of an entity or a relationship type

6

R. Ching, Ph.D. • MIS • California State University, Sacramento

Degree of Relationship TypeDegree of Relationship Type

• The number of participating entity types in a relationshipThe number of participating entity types in a relationship• Binary (two entity types)Binary (two entity types)

• Ternary (three entity types)Ternary (three entity types)

EmployeeEmployee Employee AwardsEmployee AwardsReceivesReceives

1..11..1 0..10..1

EmployeeEmployee Emp_BenefitsEmp_Benefits

Emp_TaxEmp_Tax

Net payNet pay

ReceivesReceives

Attribute of a relationship typeAttribute of a relationship type

7

R. Ching, Ph.D. • MIS • California State University, Sacramento

Recursive RelationshipRecursive Relationship

• A relationship type where the same entity participates A relationship type where the same entity participates more tan once in different rolesmore tan once in different roles

EmployeeEmployee

ManagesManages

ManagerManager

StaffStaff

A manager is an employeeA manager is an employee

Managers and staff are employees.Managers and staff are employees.

Staff are managed Staff are managed by managersby managers

1..*1..*

0..*0..*

Role name indicates the purpose an Role name indicates the purpose an entity type plays in a relationship typeentity type plays in a relationship type

8

R. Ching, Ph.D. • MIS • California State University, Sacramento

AttributesAttributes

Property of an entity or relationship typeProperty of an entity or relationship type

• Attribute domainAttribute domain– Set of values that may be assigned to a single-valued Set of values that may be assigned to a single-valued

attributeattribute

Cust_account Cust_name Cust_address Cust_phone Soc_Sec_NumCust_account Cust_name Cust_address Cust_phone Soc_Sec_NumCustomersCustomers

Cust_account Current_balance Credit_limit Active_date Expire_dateCust_account Current_balance Credit_limit Active_date Expire_dateCustomer_AccountsCustomer_Accounts

9

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attributes of AttributesAttributes of Attributes

• Simple (atomic attributes) - composed of a single Simple (atomic attributes) - composed of a single componentcomponent

• Composite - composed of multiple componentsComposite - composed of multiple components• Single valued - one value for an entitySingle valued - one value for an entity• Multi-valued - one or more values for an entityMulti-valued - one or more values for an entity• Derived - value derived from a related attribute or set of Derived - value derived from a related attribute or set of

attributesattributes

Student_ID Semester Course_IDStudent_ID Semester Course_ID

Student_ID FName MName LNameStudent_ID FName MName LName

Multi-valuedMulti-valued

Single-valuedSingle-valued

More than one More than one semestersemester, more than one , more than one course_idcourse_id

10

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attribute DomainAttribute Domain

Cust_account Cust_name Cust_address Cust_phone Soc_Sec_NumCust_account Cust_name Cust_address Cust_phone Soc_Sec_Num

CustomersCustomers

JohnJohnWilliamWilliamAnitaAnitaHomerHomer

BrownBrownTellTellBreakeBreakeSimpsonSimpson

• On an ER model, On an ER model, should customer should customer name be shown as a name be shown as a composite or simple composite or simple attribute? attribute?

• What is the attribute What is the attribute domain of domain of Cus_name?Cus_name?

Cust_first_nameCust_first_name Cust_last_nameCust_last_name

CompositeComposite

11

R. Ching, Ph.D. • MIS • California State University, Sacramento

Derived AttributesDerived Attributes

• Derived - value derived from a related attribute or set of Derived - value derived from a related attribute or set of attributesattributes

Units Units xx Grade = Grade point Grade = Grade point

Student_ID Semester Course_ID Units Grade Grade_pointStudent_ID Semester Course_ID Units Grade Grade_pointStudent_ID Semester Course_ID Units Grade Grade_pointStudent_ID Semester Course_ID Units Grade Grade_point

Student_ID Semester Course_ID Units Grade Grade_pointStudent_ID Semester Course_ID Units Grade Grade_point

Derived attributeDerived attribute

12

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attributes as KeysAttributes as Keys

Primary keyPrimary key

Candidate keyCandidate key

• Alternate key - candidate that can also be used to access Alternate key - candidate that can also be used to access an entityan entity

• Composite key - composed of multiple attributes Composite key - composed of multiple attributes (components)(components)

Uniquely identifies an entityUniquely identifies an entity

• Keys cannot change their values Keys cannot change their values (good for the life of the entity)(good for the life of the entity)

• An An efficientefficient means for identifying means for identifying an entityan entity

13

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attribute Diagrammatic RepresentationAttribute Diagrammatic Representation

Composite attributeComposite attribute

CustomersCustomers

Cust_account {PK}Cust_account {PK}Cust_nameCust_name First_nameFirst_name Middle_nameMiddle_name Last_nameLast_nameCust_addressCust_address Street_numberStreet_number Zip_code (fk)Zip_code (fk)Cust_phoneCust_phoneSoc_sec_numSoc_sec_num

Composite attributeComposite attribute

KeyKey

Foreign keyForeign key

14

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attribute Diagrammatic RepresentationAttribute Diagrammatic Representation

Composite keyComposite key

Customer_PurchasesCustomer_Purchases

Cust_account {PK}Cust_account {PK}Transaction_number {PK}Transaction_number {PK}DateDateStore_numberStore_numberPayment_typePayment_type

Foreign keyForeign key

A customer may have more than one purchaseA customer may have more than one purchase

Foreign keyForeign key

15

R. Ching, Ph.D. • MIS • California State University, Sacramento

Strong vs. Weak Entity TypesStrong vs. Weak Entity Types

• Strong Entity Type – An entity type that is not existence-Strong Entity Type – An entity type that is not existence-dependent on some other entity typedependent on some other entity type– Often referred to as Often referred to as parentparent, , ownerowner or or dominantdominant entities entities

• Weak Entity Type – An entity type that is existence-Weak Entity Type – An entity type that is existence-dependent on some other entity type.dependent on some other entity type.– Often referred to as Often referred to as childchild, , dependentdependent or or subordinate subordinate

entities entities

16

R. Ching, Ph.D. • MIS • California State University, Sacramento

Definition of a Weak Entity TypeDefinition of a Weak Entity Type

“ “An entity type that borrows all or part of its primary key. An entity type that borrows all or part of its primary key. Identifying relationships indicate the entity types that Identifying relationships indicate the entity types that supply components of the borrowed primary key.”supply components of the borrowed primary key.”

Mannino, 1999Mannino, 1999

17

R. Ching, Ph.D. • MIS • California State University, Sacramento

Strong vs. Weak Entity TypesStrong vs. Weak Entity Types

Customer_accountsCustomer_accounts

AccountNumber {PK}AccountNumber {PK}FirstNameFirstNameMiddleNameMiddleNameLastNameLastNameAddressAddressZipCodeZipCodeMembershipDateMembershipDate

Customer_PurchasesCustomer_Purchases

AccountNumber {PK}AccountNumber {PK}StoreNumber {PK}StoreNumber {PK}TransactionDate {PK}TransactionDate {PK}TransactionNumber {PK}TransactionNumber {PK}PaymentTypePaymentType

PurchasePurchase

1..11..1 0..*0..*

Which is the strong and weak entity type?Which is the strong and weak entity type?How can you tell?How can you tell?

18

R. Ching, Ph.D. • MIS • California State University, Sacramento

Strong vs. Weak Entity TypesStrong vs. Weak Entity Types

Customer_accountsCustomer_accounts

AccountNumber {PK}AccountNumber {PK}FirstNameFirstNameMiddleNameMiddleNameLastNameLastNameAddressAddressZipCodeZipCodeMembershipDateMembershipDate

Customer_PurchasesCustomer_Purchases

AccountNumber {PK}AccountNumber {PK}StoreNumber {PK}StoreNumber {PK}TransactionDate {PK}TransactionDate {PK}TransactionNumber {PK}TransactionNumber {PK}PaymentTypePaymentType

PurchasePurchase

1..11..1 0..*0..*

Which is the strong and weak entity type?Which is the strong and weak entity type?How can you tell?How can you tell?

Existent-dependenceExistent-dependence Also a FKAlso a FK

19

R. Ching, Ph.D. • MIS • California State University, Sacramento

Attributes of Relationship TypesAttributes of Relationship Types

• Attributes produced through relationship types (i.e., not Attributes produced through relationship types (i.e., not retained in the entity types)retained in the entity types)

CustomerAccountsCustomerAccounts

AccountNumberAccountNumber……

CustomerFlightsCustomerFlights

AccountNumber {PK}AccountNumber {PK}TransactionDate {PK}TransactionDate {PK}IntineraryNumber {PK}IntineraryNumber {PK}……

ReserveReserve1..11..1 0..*0..*

NumberOfItinerariesNumberOfItineraries Derived attributeDerived attribute

20

R. Ching, Ph.D. • MIS • California State University, Sacramento

Structural ConstraintsStructural Constraints

• Multiplicity – Number of possible occurences of an entity Multiplicity – Number of possible occurences of an entity type that may relate to a single occurrence of an associated type that may relate to a single occurrence of an associated entity type through a particular relationship typeentity type through a particular relationship type– One to one (1:1)One to one (1:1)– One to many (1:*)One to many (1:*)– Many to many (*:*)Many to many (*:*)

• Cardinality and participation constraintsCardinality and participation constraints– Cardinality – Describes the maximum number of Cardinality – Describes the maximum number of

possible relationship occurrences for an entity possible relationship occurrences for an entity participating in a given relationship typeparticipating in a given relationship type

Defined by business rulesDefined by business rules

21

R. Ching, Ph.D. • MIS • California State University, Sacramento

Cardinality and Participation ConstraintsCardinality and Participation Constraints

• Cardinality – Describes the maximum number of Cardinality – Describes the maximum number of possiblepossible relationship occurrences for relationship occurrences for anan entity participating in a entity participating in a given relationship typegiven relationship type

• Participation – Determines whether all or only some entity Participation – Determines whether all or only some entity occurrences participate in a relationshipoccurrences participate in a relationship– 1:1 (1..1) minimum is one – mandatory participation1:1 (1..1) minimum is one – mandatory participation– 0:1 (0..1) minimum is zero – optional participation0:1 (0..1) minimum is zero – optional participation

22

R. Ching, Ph.D. • MIS • California State University, Sacramento

CardinalityCardinality

• 1:1 (1:1 (one to oneone to one))– Each entity in Each entity in XX is associated with at most one entity in is associated with at most one entity in YY

and conversely each entity in and conversely each entity in YY is associated with at most is associated with at most one entity in one entity in XX

• 1:* (1:* (one to manyone to many))– Each entity in Each entity in XX can be associated with many entities in Y can be associated with many entities in Y

but each entity in but each entity in YY is associated with is associated with at mostat most one entity in one entity in XX..

• *:* (many to many)*:* (many to many)– Each entity in Each entity in XX can be associated with many entities in can be associated with many entities in YY

and each entity in and each entity in YY can be associated with many entities in can be associated with many entities in XX..

23

R. Ching, Ph.D. • MIS • California State University, Sacramento

CardinalityCardinality

CustomersCustomersCustomer_ID {PK}Customer_ID {PK}Customer_nameCustomer_nameCustomer_addressCustomer_addressZip_codeZip_code

OwnOwn

A customer owns a A customer owns a minimum and maximum minimum and maximum of of oneone account account

AccountsAccountsAccount_number {PK}Account_number {PK}Customer_ID {FK}Customer_ID {FK}Account_typeAccount_typeCurrent_balanceCurrent_balance

An account is owned An account is owned by a minimum and by a minimum and maximum of maximum of oneone customercustomer

1:1 Relationships1:1 RelationshipsStrong entity typeStrong entity type Weak entity typeWeak entity type

Mandatory Mandatory participationparticipation

NoteNote. This would be avoided in the logical design, but could be implemented in . This would be avoided in the logical design, but could be implemented in the physical.the physical.

1..11..1 1..11..1

24

R. Ching, Ph.D. • MIS • California State University, Sacramento

CardinalityCardinality

CustomersCustomersCustomer_ID {PK}Customer_ID {PK}Customer_nameCustomer_nameCustomer_addressCustomer_addressZip_codeZip_code

OwnOwn

A customer owns a A customer owns a minimum one and minimum one and maximum of many maximum of many accountsaccounts

AccountsAccountsAccount_number {PK}Account_number {PK}Customer_ID {FK}Customer_ID {FK}Account_typeAccount_typeCurrent_balanceCurrent_balance

1:M Relationships1:M RelationshipsStrong entity typeStrong entity type Weak entity typeWeak entity type

Mandatory Mandatory participationparticipation

An account is own by a An account is own by a minimum and maximum minimum and maximum of one customerof one customer

1..11..1 1..*1..*

25

R. Ching, Ph.D. • MIS • California State University, Sacramento

CardinalityCardinality

• *:* (many-to-many) relationship if a customer can own *:* (many-to-many) relationship if a customer can own more than one account (e.g., revolving, long-term), and more than one account (e.g., revolving, long-term), and one account can have more than one owner (e.g., joint one account can have more than one owner (e.g., joint account).account).

CustomersCustomersCustomer_ID {PK}Customer_ID {PK}Customer_nameCustomer_nameCustomer_addressCustomer_addressZip_codeZip_code

OwnOwn

A customer owns a A customer owns a minimum one and minimum one and maximum of many maximum of many accountsaccounts

AccountsAccountsAccount_number {PK}Account_number {PK}Customer_ID {FK}Customer_ID {FK}Account_typeAccount_typeCurrent_balanceCurrent_balance

An account is own by a An account is own by a minimum of one minimum of one customer and maximum customer and maximum of many customersof many customers

1..*1..* 1..*1..*

26

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation

Video_categoriesVideo_categoriesCategory_code {PK}Category_code {PK}Category_titleCategory_title

VideosVideos

Stock_number {PK}Stock_number {PK}Video_titleVideo_title……Category_code {FK}Category_code {FK}Distributor_code {FK}Distributor_code {FK}

ClassifyClassify

Entity typeEntity typePrimary keyPrimary key

AttributesAttributes

Relationship typeRelationship typeRelationship nameRelationship name

ManyManyCardinalityCardinality ZeroZeroMinimumMinimum

MaximumMaximum

1..11..1 0..*0..*

For an occurrence of videos, For an occurrence of videos, there may exist one and only there may exist one and only one video category.one video category.

For an occurrence of video For an occurrence of video categories, there may exist categories, there may exist zero to many videos.zero to many videos.

27

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation

Video_categoriesVideo_categoriesCategory_code {PK}Category_code {PK}Category_titleCategory_title

VideosVideos

Stock_number {PK}Stock_number {PK}Video_titleVideo_title……Category_code {FK}Category_code {FK}Distributor_code {FK}Distributor_code {FK}

ClassifyClassify

1..11..1 0..*0..*

DistributorsDistributorsDistributor_code {PK}Distributor_code {PK}Distributor_nameDistributor_name

0..*0..*

1..11..1

ReleaseRelease

Video categories classify videosVideo categories classify videos

Distributors release videosDistributors release videos

For an occurrence of distributors, For an occurrence of distributors, there are zero to many videosthere are zero to many videos

28

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation

Video_categoriesVideo_categoriesCategory_code {PK}Category_code {PK}Category_titleCategory_title

VideosVideos

Stock_number {PK}Stock_number {PK}Video_titleVideo_title……Category_code {FK}Category_code {FK}Distributor_code {FK}Distributor_code {FK}

ClassifyClassify

1..11..1 0..*0..*

DistributorsDistributorsDistributor_code {PK}Distributor_code {PK}Distributor_nameDistributor_name

0..*0..*

1..11..1

ReleaseRelease

Video categories classify videosVideo categories classify videos

Distributors release videosDistributors release videos

For an occurrence of videos, there is For an occurrence of videos, there is one and only one video categoryone and only one video category

29

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation

Video_categoriesVideo_categoriesCategory_code {PK}Category_code {PK}Category_titleCategory_title

VideosVideos

Stock_number {PK}Stock_number {PK}Video_titleVideo_title……Category_code {FK}Category_code {FK}Distributor_code {FK}Distributor_code {FK}

ClassifyClassify

1..11..1 0..*0..*

DistributorsDistributorsDistributor_code {PK}Distributor_code {PK}Distributor_nameDistributor_name

0..*0..*

1..11..1

ReleaseReleaseAttribute of the Attribute of the relationship typerelationship type

Number_of_videos_Number_of_videos_releasedreleased

30

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD NotationAlternate NotationAlternate Notation

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Entity typeEntity typePrimary key (underscored)Primary key (underscored)

AttributesAttributes

Relationship typeRelationship typeRelationship nameRelationship name

ManyMany(crows feet)(crows feet)

CardinalityCardinality

ZeroZero(circle)(circle)

MinimumMinimum(inside)(inside)MaximumMaximum

(outside)(outside)

31

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD NotationAlternate NotationAlternate Notation

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Entity typeEntity type

Weak entity typeWeak entity type(all four corners)(all four corners)

Minimum cardinality of oneMinimum cardinality of one((a music category has to have at least one CDa music category has to have at least one CD))

32

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation Alternative NotationAlternative Notation

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Record_label_codeRecord_label_codeRecord_labelRecord_label

Record_labelsRecord_labels

ProduceProduce

A record label is related to A record label is related to a minimum of zero and a minimum of zero and maximum of many CDsmaximum of many CDs

33

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD Notation Alternative NotationAlternative Notation

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Record_label_codeRecord_label_codeRecord_labelRecord_label

Record_labelsRecord_labels

ProduceProduceA CD is related to a A CD is related to a minimum and maximum of minimum and maximum of one record labelone record label

34

R. Ching, Ph.D. • MIS • California State University, Sacramento

ERD NotationERD NotationAlternative NotationAlternative Notation

Music_categoriesMusic_categoriesMusic_category_codeMusic_category_codeMusic_category_titleMusic_category_title

CDsCDs

Stock_numberStock_numberCD_titleCD_titleArtistArtistMusic_category_code Music_category_code Record_label_codeRecord_label_code

ClassifyClassify

Record_label_codeRecord_label_codeRecord_labelRecord_label

Record_labelsRecord_labels

ProduceProduceQuantity_producedQuantity_produced

Attribute of a relationshipAttribute of a relationship

35

R. Ching, Ph.D. • MIS • California State University, Sacramento