0% found this document useful (0 votes)
18 views

Lesson4 ERD

Uploaded by

clandestinemolo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lesson4 ERD

Uploaded by

clandestinemolo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

What is ERD?

(Entity Relationship
Diagram)
Entity Relationship Diagrams is a major data
modelling tool and will help organize the data in
your project into entities and define the
relationships between the entities.
Components of an ERD
An ERD typically consists of three different graphical
components:

1. Entity - Rectangle
2. Attributes - Ovals
3. Relationship - Diamond
Entity
A data entity is anything real or abstract about which
we want to store data.
Entity types fall into five classes: roles, events,
locations, tangible things or concepts.

Students
Attribute.
A data attribute is a characteristic common to all or most
instances of a particular entity. Synonyms include
property, data element, field.
E.g. Name, address, Employee Number, pay rate
are all attributes of the entity employee.
An attribute or combination of attributes that uniquely
identifies one and only one instance of an entity is called
a primary key or identifier.
E . g. E m pl oy ee N um ber i s a pr i m ar y k ey f o r
Employee.
Relationship

A data relationship is a natural association that exists


between one or more entities.
E.g. Employees process payments.

Employee process Payments


Cardinality
Defines the number of occurrences of one entity
for a single occurrence of the related entity.
E.g. an employee may process many payments but
might not process any payments depending on the
nature of her job.
The cardinality of a relationship can only have the
following values

Figure 3 Cardinality ERD notation


How do you get rid of many-to-many relationships?
The simple answer is that you replace the relationship with an
associative entity. This splits the relationship into two
relationships, each will be a one-to-many relationship. So the
"Department is assigned an employee" many-to-many
relationship becomes two separate relationships:

1. A single Department entity is assigned many Employee-


Department entities.
2. An Employee-Department entity includes a single
Department entity.
Figure 1
One Methodology for Developing an ERD
Typically you will start with a case study or perhaps a logical
model of the system to be developed. This document will
demonstrate how to use the following process to convert that
information into an ERD.
The process has 10 steps:
1. Identify Entities
Identify the roles, events, locations, tangible
things or concepts about which the end-users
want to store data.
2. Find Relationships
Find the natural associations between pairs of
entities using a relationship matrix.

3. Draw Rough ERD


Put entities in rectangles and relationships on line
segments connecting the entities.

4. Fill in Cardinality
Determine the number of occurrences of one entity
for a single occurrence of the related entity.
5. Define Primary Keys
Identify the data attribute(s) that uniquely identify
one and only one occurrence of each entity.

6. Draw Key-Based ERD


Eliminate Many-to-Many relationships and include
primary and foreign keys in each entity.

7. Identify Attributes
Name the information details (fields) which are
essential to the system under development.
8. Map Attributes
For each attribute, match it with exactly one entity
that it describes.

9. Draw fully attributed ERD


Adjust the ERD from step 6 to account for entities
or relationships discovered in step 8.

10. Check Results


Does the final Entity Relationship Diagram
accurately depict the system data?
Example
The above process will be illustrated by working
through the following 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. The important data fields are the
names of the departments, projects, supervisors and
employees, as well as the supervisor and employee
number and a unique project number.
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.
The important data fields are the names of the
departments, projects, supervisors and employees, as
well as the supervisor and employee number and a
unique project number.
ANSWER in Fully Attributed ERD from slide 11
Find Relationships
ü 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
Fill in Cardinality
Here's an example drawing on Figure 2 and the case study
described above.
Ø 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.
Draw Rough ERD

DEPARTMENT run by SUPERVISOR

Is
assigned

works
EMPLOYEE on
PROJECT

Figure 2
What is Relationship?

RELATIONSHIP – they exist when two or more tables


are connected or associated.
Types of Relationship
1.One – to – One Relationship | One and Only One
2.One – to Many Relationship | One or More
3. Zero or One
4.Zero or More
5.Many – to – Many Relationships
What is a many-to-many relationship?
A many-to-many relationship is a relationship that has
a "many" cardinality on either side of the relationship.
Dno. Budget
Name City
DName
Street

Customer Works DEPARTMENTs


on
Why are many-to-many relationships bad?
Two of the reasons why many-to-many relationships are bad and
should be removed from an ERD.

1.They can't be represented in relational databases.


2.You often wish to record information about a many-to-
many relationship. For example, you may wish to record
when an employee starts working on a project. With the
c u r re nt E R D yo u wo u l d n ' t b e a b l e to sto re t h i s
information. It is not information that belongs in either
the Employee or the Project entity.
Define primary keys
A primary key is an attribute, or collection of
attributes, that can be used to uniquely identify a
specific instance.
You identify primary keys by examining and
evaluating the information about the system. In this
ex am pl e, t he f o l l o w i n g a r e s p e c i f i e d a s u n i q u e
identifiers: Department Name, Supervisor Number,
Employee Number and Project Number.
Rough ERD plus Cardinality

DEPARTMENT run by SUPERVISOR

Is
assigned

works
EMPLOYEE on
PROJECT

Figure 4
Rough ERD plus Primary Keys

DEPARTMENT run by SUPERVISOR

Dep’t. Supervisor
Is Name No.
assigned
Employee Project
No. No.

works
EMPLOYEE on
PROJECT

Figure 5
Figure 6
Dep’t.
DEPARTMENT Name

Is Employee
assigned Employee No. No.
Dep’t. Name

EMPLOYEE
involves EMPLOYEE
DEPARTMENT

ERD representing Employee-Department Associative Entity


Figure 7
Project
PROJECT No.

Is Employee
assigned Employee No. No.
Project No.

EMPLOYEE Works
EMPLOYEE
PROJECT on

ERD representing Employee-Project Associative Entity


Draw an ER diagram for the example below. Be sure to indicate the
existence and cardinality for each relationship.

Husband to wife

ANSWER:

Has wife
HUSBAND WIFE
Has husband
SEATWORK
Draw an ER diagram for the example below. Be sure to
indicate the existence and cardinality for each
relationship.

1. Child to parent
2. Player to team
3. Student to course
Assignment:
Draw an ER diagram for the following. Be sure to
indicate the existence and cardinality for each
relationship.

A college runs many classes. Each class may be


taught by several teachers, and a teacher may teach
several classes. A particular class always uses the
same room. Because classes may meet at different
times or on different evenings, it is possible for
different classes to use the same room.

You might also like