Top Banner
ENTITY RELATIONSHIP DIAGRAM (ERD) Chapter 4 ICT 2073 Prepared By: Siti Hajar Ismail
40
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 Diagram

ENTITY RELATIONSHIP DIAGRAM (ERD)

Chapter 4

ICT 2073

Prepared By: Siti Hajar Ismail

Page 2: Entity Relationship Diagram

OBJECTIVES

Define terms related to entity relationship modeling,

including entity, entity instance, attribute,

relationship and cardinality, and primary key.

Describe the entity modeling process.

Discuss how to draw an entity relationship diagram.

Describe how to recognize entities, attributes,

relationships, and cardinalities.

Page 3: Entity Relationship Diagram

DATABASE MODEL

A database can be modeled as:

a collection of entities,

relationship among entities.

Database systems are often modeled using an Entity

Relationship (ER) diagram as the "blueprint" from

which the actual data is stored

Page 4: Entity Relationship Diagram

ENTITY RELATIONSHIP DIAGRAM (ERD) ER model allows us to sketch database designs

ERD is a graphical tool for modeling data.

ERD is widely used in database design

ERD is a graphical representation of the logical

structure of a database

ERD is a model that identifies the concepts or

entities that exist in a system and the relationships

between those entities

Page 5: Entity Relationship Diagram

PURPOSES OF ERD better understanding of the information to be

contained in the database

documentation tool.

to communicate the logical structure of the

database to users

Page 6: Entity Relationship Diagram

COMPONENTS OF AN ERD

An ERD typically consists of four different

graphical components:

1. Entity

2. Relationship

3. Cardinality

4. Attribute

Page 7: Entity Relationship Diagram

CLASSIFICATION OF RELATIONSHIP

Optional Relationship An Employee may or may not be assigned to a

Department A Patient may or may not be assigned to a Bed

Mandatory Relationship Every Course must be taught by at least one

Teacher Every mother have at least a Child

Page 8: Entity Relationship Diagram

For a binary relationship set the mapping cardinality

must be one of the following types:

One to one

A Manager Head one Department and vice versa One to many ( or many to one)

An Employee Works in one Department or One

Department has many Employees Many to many

A Teacher Teaches many Students and A student

is taught by many Teachers

Page 9: Entity Relationship Diagram

9

ONE-ONE AND ONE-MANY

Page 10: Entity Relationship Diagram

10

MANY-ONE AND MANY-MANY

Page 11: Entity Relationship Diagram

CARDINALITY CONSTRAINTS (CONTD.)

Page 12: Entity Relationship Diagram

CARDINALITY CONSTRAINTS EXAMPLE

In our model, we wish to indicate that each school may

enroll many students, or may not enroll any students

at all.

We also wish to indicate that each student attends

exactly one school. The following diagram indicates

this optionality and cardinality:

Page 13: Entity Relationship Diagram

CARDINALITY CONSTRAINTS EXAMPLE (CONTD.)

SCHOOL

STUDENTEach school enrolls

at least zero

and at most many

students

Each student attends

at least one

and at most one

school

Page 14: Entity Relationship Diagram

GENERAL STEPS TO CREATE AN ERD Identify the entity

Identify the entity's attributes

Identify the Primary Keys

Identify the relation between entities

Identify the Cardinality constraint

Draw the ERD

Check the ERD

Page 15: Entity Relationship Diagram

STEPS IN BUILDING AN ERD

Page 16: Entity Relationship Diagram

A SIMPLE EXAMPLE

A company has several departments. Each department

has a supervisor and at least one employee.

Employees must be assigned to at least one, but

possibly more departments. At least one employee is

assigned to a project, but an employee may be on

vacation and not assigned to any projects.

Page 17: Entity Relationship Diagram

1. IDENTIFY ENTITIES

A company has several departments. Each department

has a supervisor and at least one employee. Employees

must be assigned to at least one, but possibly more

departments. At least one employee is assigned to a

project, but an employee may be on vacation and not

assigned to any projects.

A true entity should have more than one instance

Page 18: Entity Relationship Diagram

2. FIND RELATIONSHIPS

Aim is to identify the associations, the connections

between pairs of entities.

A simple approach to do this is using a relationship

matrix (table) that has rows and columns for each of the

identified entities.

Page 19: Entity Relationship Diagram

FIND RELATIONSHIPS (CONTD.)

Go through each cell and decide whether or not there is an association. For example, the first cell on the second row is used to indicate if there is a relationship between the entity "Employee" and the entity "Department".

Page 20: Entity Relationship Diagram

3. IDENTIFIED RELATIONSHIPS Names placed in the cells are meant to

capture/describe the relationships. So you can use them like this

A Department is assigned an employee A Department is run by a supervisor An employee belongs to a department An employee works on a project A supervisor runs a department A project uses an employee

Page 21: Entity Relationship Diagram

4. DRAW ROUGH ERD

Draw a diagram and: Place all the entities in rectangles Use diamonds and lines to represent the

relationships between entities. General Examples

Page 22: Entity Relationship Diagram

DRAWING ROUGH ERD (CONTD.)

Page 23: Entity Relationship Diagram

DRAWING ROUGH ERD (CONTD.)

Page 24: Entity Relationship Diagram

DRAWING ROUGH ERD (CONTD.)

Page 25: Entity Relationship Diagram

5. FILL IN CARDINALITY Supervisor

Each department has one supervisor.

Department Each supervisor has one department. Each employee can belong to one or more departments

Employee Each department must have one or more employees Each project must have one or more employees

Project Each employee can have 0 or more projects.

Page 26: Entity Relationship Diagram

FILL IN CARDINALITY (CONTD.)

The cardinality of a relationship can only have the following values One and only one

One or more

Zero or more

Zero or one

Page 27: Entity Relationship Diagram

CARDINALITY NOTATION

Page 28: Entity Relationship Diagram

CARDINALITY EXAMPLES

A

A

A

A

B

B

B

B

Each instance of A is related to a minimum ofzero and a maximum of one instance of B

Each instance of B is related to a minimum ofone and a maximum of one instance of A

Each instance of A is related to a minimum ofone and a maximum of many instances of B

Each instance of B is related to a minimum ofzero and a maximum of many instances of A

Page 29: Entity Relationship Diagram

6. ERD WITH CARDINALITY

Page 30: Entity Relationship Diagram

EXAMPLES

Page 31: Entity Relationship Diagram

ERD FOR COURSE ENROLLMENT

Page 32: Entity Relationship Diagram

ERD FOR COURSE REGISTRATION

Page 33: Entity Relationship Diagram

ROUGH ERD PLUS PRIMARY KEYS

Page 34: Entity Relationship Diagram

7. IDENTIFY ATTRIBUTES Identify and name all the attributes essential to the system we

are studying without trying to match them to particular entities.

The only attributes indicated are the names of the departments,

projects, supervisors and employees, as well as the supervisor

and employee NUMBER and a unique project number.

Page 35: Entity Relationship Diagram

8. MAP ATTRIBUTES

For each attribute we need to match it with

exactly one entity. Often it seems like an

attribute should go with more than one entity

(e.g. Name).

Page 36: Entity Relationship Diagram

MAP ATTRIBUTES (CONTD.)

Page 37: Entity Relationship Diagram

DRAW FULLY ATTRIBUTED ERD

Page 38: Entity Relationship Diagram

38

WEAK ENTITY SET

Some entity sets in real world naturally depend on some other entity set They can be uniquely identified only if combined

with another entity set Example:

section1, section2, … become unique only if you put them into a context, e.g. csce4350

Page 39: Entity Relationship Diagram

39

WEAK ENTITY SET NOTATIONS

Double rectangles for weak entity setDouble diamond for weak entity relationshipDashed underscore for discriminator

Page 40: Entity Relationship Diagram

LEARNING OUTCOME

Define terms related to entity relationship

modeling, including entity, entity instance,

attribute, relationship and cardinality, and

primary key.

Explain the entity modeling process.

Draw an entity relationship diagram.