+ All Categories
Home > Documents > Chap4 ERM Revised

Chap4 ERM Revised

Date post: 02-Dec-2014
Category:
Upload: ay-ar-ey-valencia
View: 137 times
Download: 0 times
Share this document with a friend
Popular Tags:
61
1
Transcript
Page 1: Chap4 ERM Revised

1

Page 2: Chap4 ERM Revised

2

ENTITY RELATIONSHIP MODEL(ERM)

Page 3: Chap4 ERM Revised

3

Objectives

■ How to use Entity–Relationship (ER) modeling in database design.

■ Basic concepts associated with ER model.

■ Diagrammatic technique for displaying ER model using Unified Modeling Language (UML).

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

Page 4: Chap4 ERM Revised

Entity Relationship Modeling

■ Models business,not implementation

■ Is a well-established technique

■ Has a robust syntax

■ Results in easy-to-read diagrams…

■...although they maylook rather complex at first sight

SUPPLIER# SUPPLIER CODEo EMAIL* APPROVED* REFERENCE

OTHER ORGANIZATION

ORGANIZATIONo EMAIL* NAMEo POSTAL CODEo REGIONo STREETo TOWNo TELEPHONE NUMBERo CONTACT NAMEo CONTACT EXTENSION

MEMBERSHIP TYPE# CODE* DESCRIPTION* DISCOUNT PERCENTAGEo STANDARD FEE

MEMBERSHIP PERIOD# START DATEo ACTUAL FEE PAID

MEMBERSHIP# NUMBERo TERMINATION REASONo TERMINATION DATE

EMPLOYEE* POSITION* LAST NAMEo FIRST NAMEo OTHER INITIALSo EMAIL

BOOKING* BOOK DATEo EXPIRE DATEo NOTIFY DATEo RESERVE DATEo STAFF REMARKS

RENTAL ITEM# LINE NO* RENTAL PERIOD* PRICE PAIDo RETURN DATEo STAFF REMARKS

RENTAL* RENTAL DATEo STAFF REMARKSo COMPLETED

COPY* ACQUIRE DATE* PURCHASE COST* SHELF CODEo CONDITIONo CUSTOMER REMARKS...

REVIEW# SEQUENCE* ARTICLE* HOTo AUTHORo URL

PUBLICATION# REFERENCE* TITLEo VOLUMEo ISSUEo PUBLISH DATE

CUSTOMERo EMAIL* DESIGNATION* FIRST NAME* LAST NAMEo OTHER INITIALS* STREET* TOWN* POSTAL CODE* REGIONo HOME PHONEo WORK EXTENSIONo WORK PHONEo PHOTOGRAPHo STAFF REMARKS

CATALOG# REFERENCEo CATALOG DATEo DESCRIPTION

MOVIE* CATEGORYo AGE RATING* DURATION* MONOCHROMEo AUDIOo PREVIEW

GAME* CATEGORY* MEDIUMo MINIMUM MEMORY

TITLE# PRODUCT CODE* TITLEo DESCRIPTION

PRICE LEVEL# CODE* DESCRIPTION

PRICE HISTORY# EFFECTIVE DATE* PRICE* DEFAULT DAYS* OVERDUE RATE

for

used for

of

renewed for

of

the type of

held by

the holder of

held by

the holder of

availablefrom

thedistributor for

requestedagainst the

requestorof

authorized by

responsiblefor

the reservation for

reserved on

for

on

cancelled by

the cancellor of

approved by

responsible for

of

reviewed in

at

applied to

the rental for

fulfilled as

part of

composed of

for

rented on

approved by

responsiblefor

part of

parent organization of

acquired from

the source of

of

available as

for

defined by

managed by

the manager of

in

the source of

in

the source of

Page 5: Chap4 ERM Revised

Goals of Entity Relationship Modeling

– Capture all required information – Information appears only once– Model no information that is derivable from

other information already modeled– Information is in a predictable, logical

place

Page 6: Chap4 ERM Revised

Database Types

HierarchicalRelational

Network

ER Model

Page 7: Chap4 ERM Revised

7

ER Diagram of Branch View of

DreamHome

Page 8: Chap4 ERM Revised

8

Concepts of the ER Model

■ Entity types

■ Relationship types

■ Attributes

Page 9: Chap4 ERM Revised

9

Entity Type■ Entity type

– Group of objects with same properties, identified by enterprise as having an independent existence.

– “Something” of significance to the business about which data must be known

– A name for the things that you can list– Usually a noun

■ Entity occurrence/instances– Uniquely identifiable object of an entity type.

Page 10: Chap4 ERM Revised

Example of Entities and Instances (1)■ PERSON

■ PRODUCT

■ PRODUCT TYPE

■ EMPLOYMENT CONTRACT

■ JOB

■ SKILL LEVEL

■ TICKET RESERVATION

■ PURCHASE

■ ELECTION

■ PRINTER PREFERENCE

■ DOCUMENT VERSION

■ Mahatma Gandhi

■ 2.5 x 35 mm copper nail

■ nail

■ my previous contract

■ violinist

■ fluent

■ tonight: Hamlet in the Royal

■ the CD I bought yesterday

■ for parliament next fall

■ …

■ ...

Page 11: Chap4 ERM Revised

11

Examples of Entity Types (2)

Page 12: Chap4 ERM Revised

Entities and Sets

■ An entity represents a set of instances that are of interest to a particular business.

JOB

dish washer

waiter

cookwaitress

manager

financial controller

porter

piano player

Page 13: Chap4 ERM Revised

13

ER Diagram of Staff and BranchEntity Types

Page 14: Chap4 ERM Revised

Remarks on creating Entities

– Give the entity a unique name– Create a formal description of

the entity– Add a few attributes, if possible– Be aware of homonyms– Check entity names and descriptions regularly– Avoid use of reserved words– Remove relationship name from entity name

Page 15: Chap4 ERM Revised

15

Relationship Types

■ Relationship type– Set of meaningful associations among entity

types. – Express how entities are mutually related– Always exist between two entities (or one entity twice)

■ Relationship occurrence– Uniquely identifiable association, which

includes one occurrence from each participating entity type.

Page 16: Chap4 ERM Revised

Relationship Examples

■ EMPLOYEES have JOBS

■ JOBS are held by EMPLOYEES

PRODUCTS are classified by a PRODUCT TYPE

PRODUCT TYPE is a classification for a PRODUCT

PEOPLE make TICKET RESERVATIONS

TICKET RESERVATIONS are made by PEOPLE

Page 17: Chap4 ERM Revised

Entity Representation in Diagram

– Drawn as a “softbox”– Name singular– Name inside– Neither size,

nor position has a special meaning

During design, entities usually lead to tables.

EMPLOYEE

TICKETRESERVATION

JOB ASSIGNMENT

JOB

ORDER

EL

EC

TIO

N

Page 18: Chap4 ERM Revised

JOB

waiter

cookwaitress

manager

financial controller

porter

piano player

Employees have Jobs

Ahmed

JillAdam

Maria

EMPLOYEE

Numerical observation:

• All EMPLOYEES have a JOB

• No EMPLOYEE has more than one JOB

• Not all JOBS are held by an EMPLOYEE

• Some JOBS are held by more than one EMPLOYEE

Shintaro dish washer

Page 19: Chap4 ERM Revised

19

Semantic Net of Has Relationship Type

Page 20: Chap4 ERM Revised

20

ER Diagram of Branch Has Staff Relationship

Page 21: Chap4 ERM Revised

21

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 22: Chap4 ERM Revised

22

Binary Relationship called POwns

Page 23: Chap4 ERM Revised

23

Ternary Relationship called Registers

Page 24: Chap4 ERM Revised

24

Quaternary Relationship called Arranges

Page 25: Chap4 ERM Revised

25

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 26: Chap4 ERM Revised

26

Recursive Relationship called Supervises with Role Names

Page 27: Chap4 ERM Revised

27

Entities associated through two distinct Relationships with Role

Names

Page 28: Chap4 ERM Revised

28

Attributes■ Attribute

– Also represents something of significance to the business – Is a specific piece of information that:

• Describes• Quantifies• Qualifies • Classifies • Specifies an entity

– Property of an entity or a relationship type.

■ Attribute Domain– Set of allowable values for one or more attributes.

Page 29: Chap4 ERM Revised

Attribute Examples

Entity

EMPLOYEE

CAR

ORDER

JOB

TRANSACTION

EMPLOYMENT CONTRACT

Attribute

Family Name, Age, Shoe Size,

Town of Residence, Email, ...

Model, Weight, Catalog Price, …

Order Date, Ship Date, …

Title, Description, ...

Amount, Transaction Date, …

Start Date, Salary, ...

Page 30: Chap4 ERM Revised

EM Entities and Attributes

useraddress passwordpersonname country birth date occupation message text attachment file folder inbox outbox wastebasket

Nouns

USERAddress PasswordPERSONNameCOUNTRYBirth Date Occupation MESSAGE Text ATTACHMENT File FOLDER Inbox Outbox Wastebasket

Entities/Attributes/Instances

USER - Address - PasswordPERSON - Name - Birth Date - Occupation COUNTRY - NameMESSAGE - Text ATTACHMENT - FilenameFOLDER - Name

Entities with their Attributes

Page 31: Chap4 ERM Revised

Attributes in Diagrams• Mandatory attribute, that is, known and available for

every instance.

• Optional attribute, that is, unknown or unimportant to know for some instances.

EMPLOYEE Family Name Addresso Birth Dateo Shoe Sizeo Email

JOB Titleo Description

During design, attributes lead to columns.

**

*

Page 32: Chap4 ERM Revised

32

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.– Example: address (simple attribute) can be

subdivided into attributes of street, city, postcode

Page 33: Chap4 ERM Revised

33

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. – Eg: telephoneNo

■ 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 34: Chap4 ERM Revised

34

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 35: Chap4 ERM Revised

35

ER Diagram of Staff and Branch Entities and their Attributes

Page 36: Chap4 ERM Revised

36

Entity Type■ Strong Entity Type

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

– Characteristic:• Each entity occurrence is uniquely identifiable

using PK attribute of the entity type

■ Weak Entity Type– Entity type that is existence-dependent on some

other entity type. – Characteristic:

• Each entity occurrence cannot be uniquely identified using attributses associated with the entity type

Page 37: Chap4 ERM Revised

37

Strong Entity Type called Client and Weak Entity Type called Preference

Page 38: Chap4 ERM Revised

38

Relationship with Attributes

When to have relationship with attributes??

Page 39: Chap4 ERM Revised

39

Structural Constraints■ Main type of constraint on relationships is

called multiplicity.

■ Multiplicity - number (or range) of possible occurrences of an entity type that may relate to a single occurrence of an associated entity type through a particular relationship.

■ Represents policies (called business rules) established by user or company.

Page 40: Chap4 ERM Revised

40

Structural Constraints

■ The most common degree for relationships is binary.

■ Binary relationships are generally referred to as being:– one-to-one (1:1)– one-to-many (1:*)– many-to-many (*:*)

Page 41: Chap4 ERM Revised

41

Semantic Net of Staff Manages Branch Relationship Type

Page 42: Chap4 ERM Revised

42

Multiplicity of Staff Manages Branch (1:1) Relationship Type

Page 43: Chap4 ERM Revised

43

Semantic Net of Staff Oversees PropertyForRent Relationship Type

Page 44: Chap4 ERM Revised

44

Multiplicity of Staff Oversees PropertyForRent (1:*) Relationship Type

Page 45: Chap4 ERM Revised

45

Semantic Net of Newspaper Advertises PropertyForRent Relationship Type

Page 46: Chap4 ERM Revised

46

Multiplicity of Newspaper Advertises PropertyForRent (*:*) Relationship

Page 47: Chap4 ERM Revised

47

Structural Constraints

■ Multiplicity for Complex Relationships – Complex relationship – relationship higher

than binary– Number (or range) of possible occurrences of

an entity type in an n-ary relationship when other (n-1) values are fixed.

Page 48: Chap4 ERM Revised

48

Semantic Net of Ternary Registers Relationship with Values for Staff and Branch Entities Fixed

Page 49: Chap4 ERM Revised

49

Multiplicity of Ternary Registers Relationship

Staff of a branch registerszero client or more

Page 50: Chap4 ERM Revised

50

Summary of Multiplicity Constraints

Page 51: Chap4 ERM Revised

51

Structural Constraints■ From multiplicity we can actually identify two type

of restrictions on relationships: cardinality and participation.

■ Cardinality – Describes maximum number of possible relationship

occurrences for an entity participating in a given relationship type.

– Appears as the maximum values for the multiplicity ranges on either side of the relationship

Page 52: Chap4 ERM Revised

52

Structural Constraints■ Participation (mandatory/optional)

– determines whether all or only some entity occurrences are involved/participate in a relationship.

– All is mandatory (minimum value 1) ; only some is optional (minimum value 0)

– How to determine an entity’s participation on a diagram?• Look at the minimum value of a range at one entity. • If value is 0, then the opposite entity (in that relationship)

has a optional participation• If value is 1, then the opposite entity (in that relationship)

has a mandatory participation

Page 53: Chap4 ERM Revised

53

Multiplicity as Cardinality and Participation Constraints

Cardinality of Manages relationship is 1..1

Page 54: Chap4 ERM Revised

54

Structural Constraints

■ Why need to understand and able to differentiate between the different type of structural constraints in data model (ERD)?– Relational schemas will be created from entities-relationship in

ERD– Different type of constraints will affect the schemas created (will

be discussed in logical database design topic)

Page 55: Chap4 ERM Revised

Problem 1 : Produce an ERM for the problem description below.

Problem 1:

■ I am the manager of a training company that provides instructor-led courses in management techniques. We teach many courses, each of which has a code, a name and a fee. Introduction to UNIX and C Programming are two of our more popular courses. Courses vary in length from one day to four days. An instructor can teach several courses. Paul Rogers and Maria Gonzales are two of our best teachers. We track each instructor's name and phone number. Each course is taught by only one instructor. We create a course and then line up an instructor. The students can take several courses over time, and many of them do this. Jamie Brown from AT&T took every course we offer! We track each student's name and phone number. Some of our students and instructors do not give us their phone numbers.

55

Page 56: Chap4 ERM Revised

ERM for Problem 1

56

0..*0..*

Page 57: Chap4 ERM Revised

■ Model the USA-type geography, where the following is of interest:– States of a country including their name, population, area and date

established.– Cities including their name, population, date established and founder's

name.– Rivers including their name and length.– The capital city of each state, including the date declared.– The source of each river, i.e. the state in which it begins (which may be none)– The fact that cities may be located on particular rivers.– The fact that cities are located in states.– The length of each river within each state.– Information about states that adjoin each another, and the length of their

common border.– Assume that the names of states and rivers are unique. City names are only

unique within a state.

57

Problem 2: Produce an ERD to represent the followings:

Page 58: Chap4 ERM Revised

■ Consider the following set of requirements for a university database that is used to keep track of students' transcripts.

– The university keeps track of each student's name, student number, current address, permanent address and phone, birthdate, gender, year of study (1st, 2nd, 3rd, 4th ), major department, minor department (if any), and degree program (B.A., B.Sc., ..., Ph.D.). Some user applications need to refer to the city, county, and post code of the student's permanent address and to the student's last name.

– Each department is described by name, department code, office number and office phones. Both name and code have unique values for each department.

– Each course has a course name, description, code number, number of semester hours and offering department. The value of the code number is unique for each course.

– Each module has an instructor, semester, year, course and module number. The module number distinguishes different modules of the same course that are taught during the same semester/year; its values are 1, 2, 3, ..., up to the number of taught during each semester.

– A grade report has a student, module and grade. modules

58

Problem 3: Produce an ERD to represent the followings:

Page 59: Chap4 ERM Revised

Problem 4

■ The IT Training Group (Glasgow) has contacted you to create a conceptual model by using the Entity–Relationship data model for a database that will meet the information needs for its training program. The Company Director gives you the following description of the training group’s operating environment.

■ The Company has twelve instructors and can handle up to one hundred trainees per training session. The Company offers five advanced technology courses, each of which is taught by a teaching team of two or more instructors. Each instructor is assigned to a maximum of two teaching teams or may be assigned to do research. Each trainee undertakes one advanced technology course per training session.

■ Given this information, draw an ER diagram for IT Training Group (Glasgow).

59

Page 60: Chap4 ERM Revised

Solution – Problem 4

60

Research Instructor0..*

Assigned

1..1

Advanced

Course

1..1

Teaches

1..*

Training

Session1..*

Provides

1..1

TeachingTeam1..1

IsPartOf

0..2

Trainee1..1

Attends

1..*

Page 61: Chap4 ERM Revised

Problem 5 - Produce ERM

■ Suppose you are involved in developing a database system for the Sales Department of a company. The operation of the Department can be described as follows:

They have a file of products that they provide to their customers. Each type of product has a unique product number, as well as a description, a cost and a price. The number of the product in stock and the number allocated are updated regularly. When the number in stock decreases to the reorder level, the product is reordered in a pre-decided quantity.

They have a file of customers. Each customer is given a unique customer number. This file also contains customer names that consist of their first and last names, and customer addresses composed of street, city and postcode and the customer telephone number. Each customer has a credit limit, which is used to validate their orders.

A customer may place zero, one or more orders at a time, and an order is always placed by one customer alone. Each order is identified by a unique order number. Other information as to orders includes the date due, the total price, and the status, that is, an order may be outstanding, partially delivered, or fully delivered and invoiced.

An order may involve one or more than one type of products, and a type of products may be involved in more than one order. For each product being ordered in an order, its quantity, total price, and status (i.e., outstanding, partially delivered, or fully delivered) are recorded and updated regularly.

61


Recommended