Top Banner
1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis of an Entity-Relationship Diagram (ERD) A design technique Diagrams entities sets (with attributes) and the relationship between the entity sets. Recall previous definitions Entity refers to the entity set and not a single entity occurrence E-R diagrams are the deliverables of the design phase of information system development Depicts conceptual DB as viewed by end user We create an ERD to get agreement on the conceptual view, then we translate the ERD into the relational model for implementation 3 Entity-Relationship Model (ERM) Entities and Attributes: Chen and Crow’s Foot 4
11

Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

Jun 02, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

1

IV. Entity Relationship Modeling

2

Entity-Relationship Model (ERM) Basis of an Entity-Relationship Diagram (ERD)

A design technique Diagrams entities sets (with attributes) and

the relationship between the entity sets. Recall previous definitions

Entity refers to the entity set and not a single entity occurrence

E-R diagrams are the deliverables of the design phase of information system development Depicts conceptual DB as viewed by end user

We create an ERD to get agreement on the conceptual view, then we translate the ERD into the relational model for implementation

3

Entity-Relationship Model (ERM)Entities and Attributes: Chen and Crow’s Foot

4

Page 2: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

2

Attributes Identifier: Primary key

Composite identifier: composed of more than one attribute

Composite attribute: Attribute that can be subdivided to yield additional attributes

Simple attribute: Attribute that cannot be subdivided

Single-valued attribute: Attribute that has only a single value

Multivalued attributes: Attributes that have many values

5

Multivalued Attribute in an Entity

6

7

Representing Attributes Composite attributes

Attributes should be atomic Simple attribute for each fieldCustomer (accountId, lastName, firstName, street, city, state, zipcode)

Multi-valued attributes Represent as single-valued attribute? What’s the key?

accountId lastName firstName street city state zipcode otherUser

104 Breaux Carroll 76 Main St. Apopka FL 30458 JudyBreaux

104 Breaux Carroll 76 Main St. Apopka FL 30458 CyrusLambeaux

104 Breaux Carroll 76 Main St. Apopka FL 30458 JeanDeaux

8

Representing Attributes Represent as several new attributes, one for

each component of the original multivalued attribute

Customer (accountId, lastName, firstName, street, city, state, zipcode,spouseUser,siblingUser,childUser)

Represent as a separate tableaccountId otherUser

104 Judy Breaux

104 Cyrus Lambeaux

104 Jean Deaux

Page 3: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

3

Derived Attributes

Derived attribute: Attribute whose value is calculated from other attributes Derived using an algorithm

9

Advantages and Disadvantages of Storing Derived Attributes

10

Relationships Associations between entities that always

operate in both directions Participants: Entities that participate in a

relationship Connectivity: Describes the relationship

classification Cardinality: Expresses the minimum and

maximum number of entity occurrences associated with one occurrence of related entity

11

Connectivity and Cardinality in an ERD

12

Page 4: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

4

Relationship Participation Also called modality constraints Optional participation (“may”)

One entity occurrence does not require a corresponding entity occurrence in a particular relationship

Mandatory participation (“must”) One entity occurrence requires a

corresponding entity occurrence in a particular relationship

13

Crow’s Foot Symbols

14

CLASS is Optional to COURSE

15

COURSE and CLASS in a Mandatory Relationship

16

Page 5: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

5

17

Review Associative Entities Also known as composite or bridge entities Used to represent an M:N relationship between two

or more entities In the relational model, not necessarily the ERM

Is in a 1:M relationship with the parent entities Composed of the primary key attributes of each

parent entity May also contain additional attributes that play no

role in connective process Intersection data

18

Representing a M:N Relationship in the Relational Model

19

A Composite Entity in an ERD

20

Page 6: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

6

Relationship Degree Indicates the number of entities or

participants associated with a relationship Unary relationship: Association is

maintained within a single entity Recursive relationship: Relationship exists

between occurrences of the same entity set Binary relationship: Two entities are

associated Ternary relationship: Three entities are

associated21

Three Types of Relationship Degree in the ERM

22

23

Unary One-to-Many Relationships

A salesperson reports to exactly one sales manager, but each salesperson who does serve as a sales manager typically has several salespersons reporting to him.

There is a one-to-many relationship within salespersons.

Salesperson (also a sales manager) Salesperson

24

One-to-Many Unary Relationship

SalespersonNumber

SalespersonName

CommissionPercentage

YearOf Hire

Sales ManagerNumber

137 Baker 10 1995 186142 Smith 15 2001 137170 Taylor 18 1992 439186 Adams 15 2001198 Wang 20 1990 267204 Dickens 10 1998 267267 Perez 22 2000 285285 Costello 10 1996323 McNamara 15 1995 137361 Carlyle 20 2001 483388 Goldberg 20 1997 483411 Davidson 18 1992 137439 Warren 10 1996 186446 Albert 10 2001 483483 Jones 15 1995 285

SALESPERSON Relation

Requires the addition of one column to the relation representing the single entity involved in the unary relationship.

Page 7: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

7

25

General Hardware Company’s Product Set

Wrench Mode l A (#11)Deluxe Wrench Set (#43)

Wrench Mode l B (#14)Supreme Tool

Wrench Mode l C (#17) Set (#53)Master Wrench Set (#44)

Wrench Mode l D (#19)

Hammer Model A (#22)Grand Tool

Hammer Model B (#24) Deluxe Hammer Set (#48) Set (#56)

Hammer Model C (#28)

Drill Model A (#31 )

Drill Model B (#35 )

Figure 6.5 General Hardware Co. produ ct bill of materials.

Tools and sets of tools are sold. Many-to-many nature of products. Also: prerequisite example from Oracle lab

26

Modified Product RelationProductNumber

ProductName

UnitPrice

11 Wrench Model A 12.5014 Wrench Model B 13.7517 Wrench Model C 11.6219 Wrench Model D 15.8022 Hammer Model A 17.5024 Hammer Model B 18.0028 Hammer Model C 19.9531 Drill Model A 31.2535 Drill Model B 38.5043 Deluxe Wrench Set 23.9544 Master Wrench Set 35.0048 Deluxe Hammer Set 51.0053 Supreme Tool Set 100.0056 Grand Tool Set 109.95

PRODUCT relation

Product Numbers have been reduced to 2 digits for simplicity.

Every individual unit item and every set of tools has its own row in the relation because every item and set is available for sale.

27

Unary Many-to-Many Relationship: New RelationAssembly Part

43 1143 1444 1144 1744 1948 2248 2448 2853 4353 4853 3156 4456 4856 35

Just as a binary many-to-many relationship requires the creation of an additional relation in a relational database, so does a unary many-to-many relationship

Both Assembly and Part are foreign keys linking to the Product Number column of the PRODUCT relation

28

Ternary Relationships Involves three different

entity types.

Page 8: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

8

29

General Hardware Co.: Ternary Relationship

SalespersonNumber

SalespersonName

CommissionPercentage

YearOf Hire

137 Baker 10 1995186 Adams 15 2001204 Dickens 10 1998361 Carlyle 20 2001

(a) SALESPERSON relation.

CustomerNumber

CustomerName HQ City

0121 Main St. Hardware New York0839 Jane’s Stores Chicago0933 ABC Home Stores Los Angeles1047 Acme Hardware Store Los Angeles1525 Fred’s Tool Stores Atlanta1700 XYZ Stores Washington1826 City Hardware New York2198 Western Hardware New York2267 Central Stores New York

(b) CUSTOMER relation

ProductNumber

ProductName

UnitPrice

16386 Wrench 12.9519440 Hammer 17.5021765 Drill 32.9924013 Saw 26.2526722 Pliers 11.50

(c) PRODUCT relation.

SalespersonNumber

CustomerNumber

ProductNumber Date Quantity

137 0839 24013 2/21/2002 25361 1700 16386 2/27/2002 70137 2267 19440 3/1/2002 40204 1047 19440 3/1/2002 15186 0839 26722 3/12/2002 35137 1700 16386 3/17/2002 65361 0121 21765 3/21/2002 40204 2267 19440 4/03/2002 30204 0839 19440 4/17/2002 20

(d) SALES relation.

Existence Dependence

Existence dependence

• Entity exists in the database only when it is associated with another related entity

occurrence

Existence independence

• Entity exists apart from all of its related entities

• Referred to as a strong entity or regular entity

30

Weak Entity Also called a dependent entity Conditions

Existence-dependent Has a primary key that is partially or totally

derived from parent entity in the relationship

Database designer determines whether an entity is weak based on business rules

31

Customer Employee has no key of its own

Is defined by relationship to “owner class” Customer

Distinguished by a diagonal hash mark in each corner of its attribute area.

Employee Number is a discriminator, or partial key

Modeling Weak Entities

Page 9: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

9

33

Implementing Weak EntitiesCustomer Number

Employee Number

Employee Name

Title

0121 27498 Smith Co-Owner 0121 30441 Garcia Co-Owner 0933 25270 Chen VP Sales 0933 30441 Levy Sales Manager 0933 48285 Morton President 1525 33779 Baker Sales Manager 2198 27470 Smith President 2198 30441 Jones VP Sales 2198 33779 Garcia VP Personnel 2198 35268 Kaplan Senior Accountant

CUSTOMER EMPLOYEE relation.

Customer Number

Customer Name

Salesperson Number

HQ City

0121 Main St. Hardware 137 New York 0839 Jane’s Stores 186 Chicago 0933 ABC Home Stores 137 Los Angeles 1047 Acme Hardware Store 137 Los Angeles 1525 Fred’s Tool Stores 361 Atlanta 1700 XYZ Stores 361 Washington 1826 City Hardware 137 New York 2198 Western Hardware 204 New York 2267 Central Stores 186 New York

CUSTOMER relation.

Customer CustomerEmployee

Another Example

34

In the Relational Model…

35 36

Good Reading Bookstores

Page 10: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

10

37

Good Reading BookstoresPublisher Name

City

Country

Telephone

Year Founded

PUBLISHER Relation Author Number

Author Name

Year Born

Year Died

AUTHOR Relation Book Number

Book Name

Publication Year

Pages

Publisher Name

BOOK Relation Customer Number

Customer Name

Street

City

State

Country

CUSTOMER Relation Book Number

Author Number

WRITING Relation Book Number

Customer Number

Date

Price

Quantity

SALE Relation 38

World Music Association

39

World Music AssociationO rchestra N am e

C ity

C oun try

M usic D irec to r

O R C H E S T R A R ela tion M usician N u m ber

M usician N am e

Instru m ent

A nnual S alary

O rchestra N am e

M U SIC IA N R elation M usician N u m ber

D egree

U nivers ity

Y ear

D E G R E E R ela tion C om poser N am e

C oun try

D ate O f B irth

C O M PO S E R R ela tion C om positio n N am e

C om p oser N am e

Y ear

C O M PO S IT IO N R elation O rchestra N am e

C o m p osition N am e

C o m poser N am e

Y ear

P rice

R E C O R D IN G R ela tio n

40

Lucky Rent-A-Car

Page 11: Entity-Relationship Model (ERM) IV. Entity Relationship ...cs.furman.edu/~ktreu/csc341/lectures/chapter04.pdf1 IV. Entity Relationship Modeling 2 Entity-Relationship Model (ERM) Basis

11

41

Lucky Rent-A-CarM anufacturer Name

M anufacturer Country

Sales Rep N am e

Sales Rep Telephone

M A NU FACTU RER Relation Car Serial Number

M odel

Y ear

C lass

M anufacturer N am e

CAR Relation Repair Number

Car Serial Number

D ate

Procedure

M ileage

Repair Time

M A IN TENA N CE Relation Customer Number

Customer N am e

Customer A ddress

Customer Telephone

CUSTO M ER R elation Car Serial Number

Customer N umber

Rental D ate

Return D ate

Total Cost

REN TA L Relation

Developing an ER Diagram Create a detailed narrative of the organization’s

description of operations Identify business rules based on the descriptions Identify main entities and relationships from the

business rules Develop the initial ERD Identify the attributes and primary keys that

adequately describe entities Revise and review ERD

42