32
Chapter 11 (I) CIS458 Sungchul Hong

Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Embed Size (px)

Citation preview

Page 1: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Chapter 11 (I)

CIS458

Sungchul Hong

Page 2: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Chapter 11 - Objectives• How to use Entity–Relationship (ER) modelling in database design.

• Basic concepts associated with ER model.

• Diagrammatic technique for displaying ER model using Unified Modelling Language (UML).

• How to identify and resolve problems with ER models called connection traps.

• How to build an ER model from a requirements specification.

Page 3: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entity-Relationship Model

• ER modeling is a top-down approach to database design.

• Unified Modeling Language

Page 4: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

ER Diagram of Branch View of DreamHome

Page 5: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Concepts of the ER Model

• Entity types

• Relationship types

• Attributes

Page 6: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entity Type

• Entity type– Group of objects with same properties,

identified by enterprise as having an independent existence.

• Entity occurrence– Uniquely identifiable object of an entity type.

Page 7: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entity Type & Entity Occurrence

Employee Company

Page 8: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Examples of Entity Types

Page 9: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

ER Diagram of Staff and Branch Entity Types

Page 10: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entities (EX)

• A college is divided into several schools.• Each school is administered by a dean.• A dean is a professor• Each school is composed of several departments.• Each department offers several courses.• A course can have many sections • Each professor may teach up to four classes,

each one a section of a course. A professor may also be on a research contract and teach no classes at all.

Page 11: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Relationship Types

• Relationship type– Set of meaningful associations among entity

types.

• Relationship occurrence– Uniquely identifiable association, which

includes one occurrence from each participating entity type.

Page 12: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Semantic Net of Has Relationship Type

Branch has staff

Page 13: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

ER Diagram of Branch Has Staff Relationship

Page 14: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Relationship Types

• Degree of a Relationship– Number of participating entities in relationship.

• Relationship of degree:– two is binary;– three is ternary;– four is quaternary.

Page 15: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Binary Relationship called POwns

Page 16: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Ternary Relationship called Registers

Page 17: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Question

• Can three binary relationships substitute a ternary relationship? (In general)

Page 18: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Quaternary Relationship called Arranges

Page 19: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Relationship Types

• Recursive Relationship– Relationship type where same entity type

participates more than once in different roles.

• Relationships may be given role names to indicate purpose that each participating entity type plays in a relationship.

Page 20: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Recursive Relationship called Supervises with Role Names

Page 21: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entities associated through two distinct Relationships with Role Names

Page 22: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Attributes

• Attribute– Property of an entity or a relationship type.

• Attribute Domain– Set of allowable values for one or more

attributes.

Page 23: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Attributes• Simple Attribute

– Attribute composed of a single component with an independent existence.

• Composite Attribute– Attribute composed of multiple components,

each with an independent existence.

Page 24: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Attributes• Single-valued Attribute

– Attribute that holds a single value for each occurrence of an entity type.

• Multi-valued Attribute– Attribute that holds multiple values for each

occurrence of an entity type.

Page 25: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Attributes

• Derived Attribute– Attribute that represents a value that is

derivable from value of a related attribute, or set of attributes, not necessarily in the same entity type.

Page 26: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

car1((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))

car2

((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))car3

((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))

.

.

.

CARRegistration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

Page 27: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Keys• Candidate Key

– Minimal set of attributes that uniquely identifies each occurrence of an entity type.

• Primary Key– Candidate key selected to uniquely identify each

occurrence of an entity type.

• Composite Key– A candidate key that consists of two or more attributes.

Page 28: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Primary Key (EX)

• staffNo, name, position salary, totalStaff

• branchNo, address {street, city, zip code, telephone number[1..3]}

• Patient number, patient name, drug number, drug name, description, dosage, method of admin, units per day, start date, finish date.

Page 29: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

ER Diagram of Staff and Branch Entities and their Attributes

Page 30: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Entity Type• Strong Entity Type

– Entity type that is not existence-dependent on some other entity type.

• Weak Entity Type– Entity type that is existence-dependent on

some other entity type.

Page 31: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Strong Entity Type called Client and Weak

Entity Type called Preference

Page 32: Chapter 11 (I) CIS458 Sungchul Hong. Chapter 11 - Objectives How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated

Relationship called Advertises with Attributes

N P D C

N1 P1 1 10

N1 P2 1 10

N2 P1 1 20