lecture5

CS 4310: Software Engineering
Lecture 5
Entity Relationship Modelling
Entity-Relationship Model
Technique for carrying out the conceptual and logical
design of the system
A widely accepted data modelling approach
3 basic notions:
» entities
» attributes
» relationships
2
What is an entity?
An entity is an object that can be identified
in the users’ work environment and that
users want to track.
3
Entities
• An entity is a thing or object in the real world
(within the application context)
• An entity has a set of properties which uniquely
identify it.
• An entity is represented as a rectangle in an ER
diagram
Project
4
What is an Attribute?
An attribute describes a characteristic of an entity
For example:
- An entity: Employee
- Has attributes:
» Employee_Name
» Extension
» Date_Of_Hire
5
Attributes
Example:
Project = (proj_name, location, budget,
start_date, end_date)
Represented as ellipses in an ER diagram
budget
location
proj_name
6
Project
start_date
end_date
What are Relationships?
Relationships are associations between entities
which express some real world relationship
Project
Employs
Employee
• Project and Employee participate in the employs
relationship
• The function that an entity plays in a relationship
7 is called that entity’s role
Relationship Sets
• There can be more than
one relationship between
entities.
• There can be recursive
relationships that can
indicate roles for clarity.
• A relationship can also
have descriptive attributes.
8
starts at
Road
Town
ends at
manager
works for
Employee
worker
date
Client
orders
Book
Degree of Relationships
Refers to the number of entities participating in a relationship
Most relationships are binary (degree 2), but can also have
ternary (degree 3) relationships.
Name
proj_name
location
Project
Hires
Contractor
Address
budget
end_date
start_date
Contract
number
9
end_date
start_date
value
Mapping Cardinalities
Express the number of entities to which another entity can
be associated via a relationship
For a binary relationship, the mapping cardinality can be
one of the following:
•
•
•
•
10
one to one
one to many
many to one
many to many
Cardinality Examples
A person has only one ID book
and an ID book belongs to only
1 person
A person can own many cars
(possibly 0), but a car only has
1 owner
A person can own many houses
and a house can have multiple
owners
11
Person
owns
ID Book
Person
owns
Car
Person
owns
House
Design Issues
Entity or Attribute?
• Example: should location be an entity or an attribute?
• can a project be in more than 1 location?
Entity or Relationship?
• generally: relationships for actions between entities
• whatever “makes sense” in application context
12
ER Diagram Symbols
Entity Set
Attribute
One-to-one link
Many-to-one link
Many-to-many link
Relationship
13
Example ERD
budget
start_date
ID
end_date
surname
first_name
proj_name
location
Project
employs
Employee
position
year_joined
eliminates
start_date
species
Alien
14
area
end_date
year_left
ER Design: Where to Start
• Identify entity sets
• Describe the entity sets with attributes
• Specify relationships and cardinalities
15
Simple Modelling Example
• Every department within the company is in
only one division.
• Each division has more than one department
in it.
• There is no upper limit on the number of
departments that a division can have.
16
1. Define Entities
Division
Department
Employee
17
2. Define Relationships
Division
contains
Department
manages
Employee
18
3. Define Cardinality
Division
contains
Department
manages
Employee
19
Standard Notation
A plain rectangle is used to
represent the entity type.
INVOICE
A labeled line to represent the
relationship.
is sent by
20
A
B
1:1
A
B
1:N
Diagram with Standard Notation
Division
contains
Department
manages
Employee
21
Notation Examples
COURSE
has enrolled
STUDENT
ONE course has enrolled ONE or MORE students.
ONE student is enrolled on ONE course.
LOAN
refers to
BOOK
ONE loan refers to ONE book.
ONE book is referred to ONE loan.
22
Many-to-Many Relationship Example
• Any one supplier might supply more than
one kind of part.
• Any one kind of part might be bought
from a number of different suppliers.
SUPPLIER
23
supplies
PART
More Examples
Customer
Customer
Teachers
24
is associated
can place
teach
Property
Order
Students
Example - Simple Hospital System
WARD
has
assigned
NURSE
25
DOCTOR
accommodates
cares
for
treats
AILMENT
PATIENT
suffers
from
College System
DEPARTMENT
is_in
offers
COURSE
LECTURER
teaches
enrols
STUDENT
26
Your Project Work
• Develop Requirements Document.
• Think about your system’s entities and relationships
27