entity relationship diagram (erd) - mohtaramimohtarami.com/wp-content/uploads/2014/07/erd.pdf · do...

Post on 06-Feb-2018

242 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Entity

Relationship

Diagram (ERD)

مدلسازی اطالعات سازمان

A database is a collection of data that is organized in such a manner that its contents can be readily accessed, managed and updated

An Entity Relationship model (ERM) may be used to aid the development of a

database .An ER model may be represented pictorially by ERDs

Introduction

What is Conceptual Database Design?

Process of describing the data, relationships between the data, relationships between the data, and the constraints on the data.

After analysis - Gather all the essential data required and understand how the data are related

The focus is on the data, rather than on the processes. The output of the conceptual database design is a Conceptual Data Model ( +

Data Dictionary)

Introduction

What is a Data Model?

A detailed model that captures overall structure of organizational data while being independent of any implementation considerations

Data Model

Rationale for using Data

Modelling?

Typically data modelling is carried out parallel with other requirements analysis and structuring steps during the systems analysis phase

During this phase a data model is developed for the current system

Following this, the data model supporting the scope and requirements of the proposed system is developed

Data Model

Entity-Relationship (ER) Modeling.

ER Modeling is a top-down approach to database design. Entity Relationship (ER) Diagram Data modelling involves examining the data objects in a system

and identifying the relationship between these objects Notation uses three main constructs

Data entities

Relationships

Attributes

Chen Model &

Crow’s Foot

Model

Entity Relationship

Two Styles of ERD’s

The two most popular approaches to

construct entity relationship diagrams are:

SSADM

Chen ERD

Visio provides stencils for constructing

ERD’s using these approaches

ERD

ERD Symbols

SSADM Chen

Entity

Attribute

Relationship

8

Department

Staff No.

employs

Staff No

Department

Department 2

2

employs

ERD

Person, place, object, event

or concept about which data

is to be maintained

named property or

characteristic of an

entity

Association

between the

instances of one or

more entity types

Represents a set or collection of

objects in the real world that

share the same properties

Chen Notation

EntityName Verb Phrase AttributeName

An Entity

An entity is a thing of interest to a system about which information is kept

For example in a Hospital Administration System, some likely entities would include: Patient, Doctor, Operation, Ward

Each of these things are of interest to the system and would have data stored about them

ERD

Attributes

A key attribute uniquely identifies a specific occurrence of an entity

This may also be referred to as a primary key

Examples of primary keys include:

ISBN

Student Number

Staff ID

ERD

Identifier Attributes

Candidate key

Attribute (or combination of attributes) that uniquely

identifies each instance of an entity type

Some entities may have more than one candidate

key

Ex: A candidate key for EMPLOYEE is Employee_ID, a second

is the combination of Employee_Name and Address.

If there is more than one candidate key, need to make a

choice.

Identifier

A candidate key that has been selected as the

unique identifying characteristic for an entity type

Referential Attributes

Name IdNum DeptID Email

Ali 105 LG ali@a.com

Mary 106 IT mary@a.com

John 107 ENG john@a.com

Lim 108 IT lim@a.com Instance of Lecturer.

Referential attribute: Ties the lecturer entity to

another entity that is department.

Make Reference to another instance in another table

Relationships

Associations between instances of one or more entity types that is of interest

Given a name that describes its function.

• relationship name is an active or a passive verb.

Author Book

Relationship name:

writes

An author writes one or more books

A book can be written by one or more authors.

Degree of Relationships

Degree: number of entity types that participate in a

relationship

Three cases

Unary: between two instances of one entity type

Binary: between the instances of two entity types

Ternary: among the instances of three entity types

Cardinality and Connectivity

Relationships can be classified as either one – to – one

one – to – many

many – to –many

Cardinality : minimum and maximum

number of instances of Entity B that can

(or must be) associated with each

instance of entity A.

Connectivity

Cardinality and Connectivity

Professor Class teaches

A professor teaches class OR

A class is taught by professor

How Many??

Professor Class teaches

Connectivity

Chen Model

1 to represent one.

M to represent many

Crow’s Foot

many

One

One or many

1

M

Mandatory one , means (1,1)

Optional? – we’ll see after this

2.5 Binary Relationships

1:M relationship

Relational modeling ideal

Should be the norm in any relational database design

The 1: M relationship between PAINTER and PAINTING

The Implemented 1:M relationship between PAINTER and PAINTING

Binary Relationships

1:1 relationship

Should be rare in any relational database design

A single entity instance in one entity class is

related to a single entity instance in another entity

class

Could indicate that two entities actually belong in

the same table

The 1:1 Relationship Between PROFESSOR and DEPARTMENT

The Implemented

1:1 Relationship

Between

PROFESSOR

and

DEPARTMENT

Binary Relationships

M:N relationships

Must be avoided because they lead to data

redundancies.

Can be implemented by breaking it up to produce a

set of 1:M relationships

Can avoid problems inherent to M:N relationship by

creating a composite entity or bridge entity

This will be used to link the tables that were

originally related in a M:N relationship

The composite entity structure includes-as foreign

keys-at least the primary keys of the tables that

are to be linked.

The M:N Relationship Between STUDENT and CLASS

This CANNOT be implemented as shown next…..

Bowser

Smithson

Accounting 1 (ACCT-211)

Intro to Microcomputing (CIS-220)

Intro to Statistics (QM-261)

The tables have many redundancies!!

+ CLASS_CODE

CLASS_CODE

+ STU_NUM

Changing the M:N relationship to TWO 1:M relationships

Converting the M:N relationship into TWO 1:M relationships

Foreign keys reference the primary keys in the

other tables of which it has a relationship with

The database designer has 2 main options to

define a composite table’s primary key:

either

use the combination of those foreign

keys or create a new primary key.

Mandatory vs. Optional Cardinalities

Specifies whether an instance must exist or can be

absent in the relationship

Lecturer Class handles

A Lecturer may handle zero or many classes.

A class is handled by one and only one Lecturer.

Optional Mandatory

(0,N) (1,1)

Lecturer Class

(0,N) (1,1)

handles 1

M

How to Evaluate a Data Model?

A good data model has the

following:

Accuracy and completeness

Non redundancy

Enforcement of business rules

Data Reusability

Stability and Flexibility

Communication Effectiveness

Simplicity

A Common Mistake

Modeling the business processes or functions

instead of the data.

What data we want to keep??

We are interested in modeling the data,

NOT the processes or functions that use

or generate those data.

Example:

Member Books Searches

M N

Is this part of the data requirement?

Are we interested to know the books searched by the members?

If answer is NO, then DO NOT include that as a relationship.

Use other appropriate diagramming techniques to capture the business

processes such as Data Flow Diagram.

Do not mix up the use of ER Modeling with DFD.

Choosing Entities

Example

A sale always starts with a customer

receiving an estimate. The estimate then becomes an order. An order can be for

one or more stock items. Each stock

item belongs to a certain stock category

(e.g. taps, sinks, cupboards etc.)

ERD

An Attribute An attribute is an item of data held about an

entity

In computer systems an attribute is a field of

information

Example : Sales System

Entity : Customer

Attributes : Customer Name, Customer Address,

Customer Phone Number

ERD

For Example

In a Sales System, customer name and

address are attributes of the entity customer.

The primary key is likely to be Customer Code or Customer ID as the unique

identifier for each customer in the system.

ERD

Designing a System:

Data Flow Diagramming

External entities, process, data stores

Answers question: “How will the data be used?”

Entity-Relationship Diagramming (ERDs)

Depict entities and their relationships amongst each other

Answers question: “What data will be captured in the database, and how will the data relate to each other?”

DFD Vs. ERD

Example : Babysitter

Service

The AITP Service Club wants to run a

babysitting service. Customers call to

request a sitter and the Club Coordinator

assigns an employee to sit for the

customer from a list of employees

available for the particular day

requested.

ERD Example

Babysitting System

Data is used to:

Assign employee to job

Determine availability

Data to be captured in database:

Employee data

Job data

Customer data

ERD Example

Entity-Relationship Model

A logical representation of the data of an

organization or business area in graphical

form

ERM

ERD - Babysitter Service

Employee

Job

Customer

assigned to Related to

ERD Example

Babysitting System Employee

Attributes: EmpID, Name,

Address, Phone Number,

Available Hours, JobNo Job

Attributes: JobNo, JobDate,

JobTime, EmpID Customer

Attributes: CusNo, Name,

Address, Phone Number, JobNo

ERD Example

Entity Instance

An entity instance is a single occurrence of an

entity type.

An entity type is described just once in a data

model while many instances of that data type

may be represented by data stored in the system.

There is one EMPLOYEE entity type in most

organisations but there may be hundred or

thousands of instances of this entity type in the

company.

42

Choosing Entities

Example

A sale always starts with a customer

receiving an estimate.The estimate then

becomes an order. An order can be for

one or more stock items. Each stock

item belongs to a certain stock category

(e.g. taps, sinks, cupboards etc.)

ERD Example

From the narrative we can deduce:

An Estimate becomes and Order

An Estimate is issued to a particular Customer

An Estimate refers to a Stock Item(s)

An Order is placed by the Customer

An Order refers to a Stock Item(s)

A Stock Item refers to a particular Stock Category

ERD Example

Order System: ERD

Customer

Order

Stock Item

Stock Category

Estimate

Places

Refers to

Becomes

Issued to

Refers to

Refers to

ERD Example

Entity Primary Key Other Attributes

Estimate Estimate Number Date

Customer Number

Stock Item Code

Order Order Number Same as Estimate

Customer Customer Number Customer Name

Customer Address

Credit Limit

Stock Item Stock Item Code Description

Number in Stock

Supplier Code

Stock Category Category Code Category Description

46

ERD Example

Entity Instance

An entity instance is a single occurrence of an entity type.

An entity type is described just once in a data model while many instances of that data type may be represented by data stored in the system.

There is one EMPLOYEE entity type in most organisations but there may be hundred or thousands of instances of this entity type in the company.

ERD Example

ERD Relationships

A relationship is an association between two

entities that is important to the system.

We must also consider the extent to which each

entity is related to another.

ERD Example

The Cardinality of a

Relationship Cardinality defines the minimum and maximum

number of occurrences of one entity for a single occurrence of the other

From the previous example we can say that:

A customer can place several orders if they wish

But an order can only be placed by one customer

ERD Example

Cardinality

Cardinality is bi-directional

This means that it must be defined for

both directions of the entity relationship.

ERD Example

One-to-One Relationship

(1:1) A one-to-one relationship occurs where a single

occurrence of one entity relates to one occurrence

of a second entity.

Estimate Order

An estimate can only become one order and an order is derived from one estimate.

becomes

ERD Example

One-to-Many

Relationship(1:N)

One-to-Many relationships occur when a

single entity instance is related to many

occurences of a second entity.

Customer Estimate

One customer can be issued with many estimates (the relationship is described as one-to-many)

is issued with

ERD Example

Many-to-Many Relationship

(N:M)

Many-to-many relationships occur

where many instances of an entity

relate to many instances of a

second entity

These relationships usually contain a

hidden entity which should be

extracted

Usually N:M relationships are broken

into one or more pairs of one-to-

many relationships

ERD Example

N:M

Many estimates refers to many stock items

(or many stock items are referred to by

many estimates)

Estimate Stock Item Refers to

ERD Example

Sales ERD

Customer

Order

Stock Item

Stock Category

Estimate

Places

Refers to

Becomes

Issued to

Refers to

Refers to

ERD Example

Cardinality Optional Cardinality

Where the analyst considers whether an

entity occurrence at one end of the

relationship can ever be present in the

system without the presence of the

corresonding occurrence of the entity

at the other end of the relationship

Mandatory Cardinality

When the occurrence of the entity at

either end of the relationship must be

present in the system

ERD Example

Mandatory - Mandatory

Some relationships are mandatory and

some are optional

Doctor Patient Is responsible for

A doctor must be responsible for one or more patients and a patient must be registered with one and only one doctor

Registered with

ERD Example

Optional – Mandatory

Doctor PROJECT Is responsible for

A doctor may be responsible for one or more patients and a patiente must be registered with one and only one doctor

Registered with

ERD Example

Mandatory – Optional

A doctor must be responsible for one of

more patients and a patient may be

registered with one and only one doctor

59

Doctor Patient

Is responsible for

Registered with

Optional – Optional

A doctor may be responsible for one or

more patients and a patient may be

registered with one and only one doctor

Doctor Patient

Is responsible for

Registered with

ERD Example

Relationship Cardinality Graphic Cardinality

Exactly 1

0 or 1

1 or more

0 or many

More than 1 61

ERD Example

Note

|| denotes 1 and only

ERD Example

top related