You are on page 1of 35

Entity-Relationship Diagram (ERD)

Yves Wautelet
Content
• What is an Entity Relationship Diagram (ERD)?
• What are Entities in an ERD?
• What are Attributes in an ERD?
• What are Relationships in an ERD?
• How to build an ERD
Database Design
• Conceptual
Before we look
design
at how to create and use a database we’ll look at how to design
oneBuild a model independent of the choice of DBMS
o

• Logical
Need todesign
consider
o What tables,
Create keys, and
the database constraints
in a given DBMSare needed?
• o What is the database going to be used for?
Physical design
o How the database is stored in hardware
Entity Relationship Diagram
• The purpose of an ERD is to capture the richest possible understanding of the
meaning of data necessary for an information system or organization.

• ERDs are made from Entities, Attributes, and Relations.


University Entity-Relationship Diagram
What is an Entity?
• An Entity is an abstraction of similar things

• Entities represent objects or things of interest


o Physical things like students, lecturers, employees, products
o More abstract things like modules, orders, courses, projects

• An Entity has its own identity that distinguishes it from other entities.
o Examples:
• Person: PROFESSOR, STUDENT
• Place: STORE, UNIVERSITY
• Object: MACHINE, BUILDING
• Event: SALE, REGISTRATION
• Concept: ACCOUNT, COURSE
Diagramming Entities
• In an E/R Diagram, an entity is usually drawn as a box with rounded corners
• The box is labelled with the name of the class of objects represented
ID
by that
Lecturer
entity
Name Course

Tutors Student

Module Studies
Attributes
• Attributes are facts, aspects, properties, or details about an entity
o Students have IDs, names, courses, addresses, …
o Modules have codes, titles, credit weights, levels, …

• Attributes have
o A name
o An associated entity
o Domains of possible values
o Values from the domain for each instance of the entity they are belong to
Diagramming Attributes
• In an E/R Diagram attributes may be drawn as ovals
• Each attribute is linked to its entity by a line ID
Lecturer
• The name of the attribute is written in the oval
Name Course

Tutors Student

Module Studies
Relationships
• Relationships are an association between two or more entities
o Each Student takes several Modules
o Each Module is taught by a Lecturer
o Each Employee works for a single Department

• Relationships have
o A name
o A set of entities that participate in them
o A degree - the number of entities that participate (most have degree 2)
o A cardinality
Cardinality Ratios
• One
Eachtoentity
one in(1:1)
a relationship can participate in zero, one, or more than one
o Each lecturer
instances has arelationship
of that unique office
•• One to many
This leads (1:M) types of relationships
to different
o A lecturer may tutor many students, but each student has just one tutor
• Many to many (M:M)
o Each student takes several modules, and each module is taken by several students
Basic Cardinality Type

• 1-to-1 relationship

• 1-to-M relationship

• M-to-M relationship
Cardinality con’t
Diagramming Relationships
• Relationships are links between two entities
Lecturer ID
• The name is given in a diamond box
• The ends of the link show cardinality Name Course

Tutors Student

Module Studies

One and only one Many


Making E/R Models
• General
To make guidelines
an E/R model you need to identify
o Since entities are things or objects they are often nouns in the description
Enitities
o Attributes are facts or properties, and so are often nouns also
o Relationships
Verbs often describe relationships between entities
o Cardinality ratios

• from a description, in real life you mostly get it from interviews


Example
A university consists of a number of departments. Each department offers several
courses. A number of modules make up each course. Students enrol in a
particular course and take modules towards the completion of that course. Each
module is taught by a lecturer from the appropriate department, and each lecturer
tutors a group of students
Example - Entities
A university consists of a number of departments. Each department offers
several courses. A number of modules make up each course. Students enrol in
a particular course and take modules towards the completion of that course. Each
module is taught by a lecturer from the appropriate department, and each
lecturer tutors a group of students
Example - Relationships
• A university consists of a number of departments. Each department offers
several courses. A number of modules make up each course. Students enrol in
a particular course and take modules towards the completion of that course.
Each module is taught by a lecturer from the appropriate department, and each
lecturer tutors a group of students
Example - E/R Diagram

Entities: Department, Course, Module, Lecturer, Student

Department

Course Module Lecturer

Student
Example - E/R Diagram

Each department offers several courses

Offers Department

Course Module Lecturer

Student
Example - E/R Diagram

A number of modules make up each courses

Offers Department

Course Includes Module Lecturer

Student
Example - E/R Diagram

Students enrol in a particular course

Offers Department

Course Includes Module Lecturer

Enrols In Student
Example - E/R Diagram

Students … take modules

Offers Department

Course Includes Module Lecturer

Takes

Enrols In Student
Example - E/R Diagram

Each module is taught by a lecturer

Offers Department

Course Includes Module Teaches Lecturer

Takes

Enrols In Student
Example - E/R Diagram

a lecturer from the appropriate department

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student
Example - E/R Diagram

each lecturer tutors a group of students

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors


Example - E/R Diagram

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors


Entities and Attributes
• General
Sometimes
guidelines
it is hard to tell if something should be an entity or an attribute
o Entities
They both
canrepresent
have attributes
objectsbut
or facts
attributes
abouthave
the world
no smaller parts
o They arecan
Entities both
have
often
relationships
represented between
by nounsthem,
in descriptions
but an attribute belongs to a single entity
Example
We want to represent information about products in a database. Each product
has a description, a price and a supplier. Suppliers have addresses, phone
numbers, and names. Each address is made up of a street address, a city, and a
postcode.
Example - Entities/Attributes
• Entities
Products,or suppliers,
attributes:and addresses all have smaller parts so we can make them
• product
entities
• description
• The• others
price have no smaller parts and belong to a single entity
• supplier
• address
• phone number
• name
• street address
• city
• postcode
Example - E/R Diagram

Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode


Example - Relationships
• Each supplier
product has
has aansupplier
address
o A supplier
Each product
hashas
a single
a single
address
supplier but there is nothing to stop a supplier supplying many
o products
It does not seem sensible for two different suppliers to have the same address
o
o A
A many
one toto one
one relationship
relationship
Example - E/R Diagram

Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode


One to One Relationships
• Example
Some relationships
- the supplier-address
between entities,
relationship
A and B, might be redundant if
o Is isone
It a 1:1
to one
relationship between A and B
o Every A supplier
is related
hastoan
a address
B and every B is related to an A
o We don’t need addresses that are not related to a supplier
Redundant Relationships
• We can merge the two entities that take part in a redundant relationship together
o They become a single entity
a x
o The new entity has all the attributes of the old one
b A B y

c z

a x

b AB y

c z

You might also like