You are on page 1of 26

Exampl

e
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

ENTITYRELATIONSHIP MODELLING
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

ENTITYRELATIONSHIP MODELLING
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

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Entities: Department, Course, Module, Lecturer, Student

Department

Course Module Lecturer

Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Each department offers several courses

Offers Department

Course Module Lecturer

Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
A number of modules make up each courses

Offers Department

Course Includes Module Lecturer

Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Students enrol in a particular course

Offers Department

Course Includes Module Lecturer

Enrols In Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Students … take modules

Offers Department

Course Includes Module Lecturer

Take
s

Enrols In Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Each module is taught by a lecturer

Offers Department

Course Includes Module Teache Lecturer


s

Take
s

Enrols In Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
a lecturer from the appropriate department

Offers Department Employs

Course Includes Module Teache Lecturer


s

Take
s

Enrols In Student

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
each lecturer tutors a group of students

Offers Department Employs

Course Includes Module Teache Lecturer


s

Take
s

Enrols In Student Tutors

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram
Offers Department Employs

Course Includes Module Teache Lecturer


s

Take
s

Enrols In Student Tutors

ENTITYRELATIONSHIP MODELLING
Entities and
Attributes
Sometimes it is hard to tell
if something should be an
General guidelines
◦Entities can have attributes but
entity or an attribute attributes have no smaller
◦They both represent objects parts
or facts about the world ◦Entities can have relationships
◦They are both often between them, but an
represented by nouns attribute belongs to a single
in descriptions entity

ENTITYRELATIONSHIP MODELLING
Exampl
e product has a description, a price and a supplier. Suppliers
We want to represent information about products in a database.
Each
have addresses, phone numbers, and names. Each address is made
up of a street address, a city, and a postcode.

ENTITYRELATIONSHIP MODELLING
Example -
Entities/Attributes
Entities or
attributes:
Products, suppliers, and
addresses all have smaller
◦product parts so we can make
◦description them entities
◦price
◦supplier
The others have no smaller
◦address parts and belong to a
◦phone number single entity
◦name
◦street address
◦city
◦postcode

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

ENTITYRELATIONSHIP MODELLING
Example -
Relationships
Each product has a supplier
◦Each product has a single
Each supplier has an
address
supplier but there is nothing ◦A supplier has a single address
to stop a supplier supplying
◦It does not seem sensible for
many products
two different suppliers to
◦A many to one relationship
have the same address
◦A one to one relationship

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

ENTITYRELATIONSHIP MODELLING
One to One
Relationships
Some relationships
between entities, A and B,
Example - the
supplier- address
might be redundant if relationship
◦It is a 1:1 relationship ◦Is one to one
between A and B ◦Every supplier has an
◦Every A is related to a B and address
every B is related to an A ◦We don’t need
addresses that
are not related to a
supplier

ENTITYRELATIONSHIP MODELLING
Redundant
Relationships
We can merge the two
entities that take part in
a x

a redundant relationship b A B y
together
◦They become a single
c z
entity
◦The new entity has all the
attributes of the old one a x

b AB y

c z

ENTITYRELATIONSHIP MODELLING
Example - E/R
Diagram Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

ENTITYRELATIONSHIP MODELLING
Making E/R
Diagrams
From a description of the
requirements identify
Draw the E/R diagram
and then
the ◦Look at one to one
◦Entities relationships as they might be
◦Attributes redundant
◦Look at many to many
◦Relationships
relationships as they might
◦Cardinality ratios of the need to be split into two one
relationships to many links

ENTITYRELATIONSHIP MODELLING
Debugging
Designs
With a bit of practice E/R
diagrams can be used to Student
plan queries
◦You can look at the diagram How can you
and figure out how to find Has find a list of
useful information students who
◦If you can’t find the are enrolled
Enrolment in Database
information you need, you
may need to change the systems?
design
In

Module

ENTITYRELATIONSHIP MODELLING
Debugging
Designs
ID
Student
(3) For each instance of Enrolment in the
result of (2) find the corresponding Student
Name

Has

ID (2) Find instances of the Enrolment entity


Enrolment with the same Code as the result of (1)
Code

In

Code (1) Find the instance of the Module entity with


Module title ‘Database Systems’
Title
ENTITYRELATIONSHIP MODELLING
TA
“ASK
database will be made to store information about
patients in a hospital. On arrival, each patient’s
personal details (name, address, and telephone
number) are recorded where possible, and they are
given an admission number. They are then assigned
to a particular ward (Accident and Emergency,
Cardiology, Oncology, etc.). In each ward there are a
number of doctors and nurses. A patient will be
treated by one doctor and several nurses over the
course of their stay, and each doctor and nurse may
be involved with several patients at any given time.”
ENTITYRELATIONSHIP MODELLING
ER Diagram
Draw an ER Diagram of a hospital. A hospital has
many departments. Departments have different
specialist doctors . Each doctor is identified by
ID, name and specialization. A doctor checks or
treats many patients. Whenever a patient visits ,
he is given a Patient ID and Name, address and
contact number is recorded. Many nurses checks
many patients in hospital. After checking, a
patient is shifted to ward which has ward no and
ward type.

You might also like