Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Entity/Relationship Modelling: Database Systems Lecture 4 Natasha Alechina

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 38

Entity/Relationship Modelling

Database Systems Lecture 4


Natasha Alechina
In This Lecture
• Entity/Relationship models
• Entities and Attributes
• Relationships
• Attributes
• E/R Diagrams
• For more information
• Connolly and Begg chapter 11
• Ullman and Widom chapter 2

Entity Relationship Modelling


Database Design
• Before we look at • Conceptual design
how to create and • Build a model
use a database we’ll independent of the
look at how to choice of DBMS
design one • Logical design
• Need to consider • Create the database
in a given DBMS
• What tables, keys,
and constraints are • Physical design
needed? • How the database is
• What is the database stored in hardware
going to be used for?
Entity Relationship Modelling
Entity/Relationship Modelling
• E/R Modelling is used • Example
for conceptual design • In a University
• Entities - objects or database we might
have entities for
items of interest
Students, Modules and
• Attributes - facts Lecturers. Students
about, or properties might have attributes
of, an entity such as their ID,
• Relationships - links Name, and Course, and
could have
between entities
relationships with
Modules (enrolment)
and Lecturers
(tutor/tutee)
Entity Relationship Modelling
Entity/Relationship Diagrams
• E/R Models are often Lecturer ID

represented as E/R Name Course


diagrams that
• Give a conceptual
view of the database Tutors Student
• Are independent of
the choice of DBMS
• Can identify some
problems in a design Module Studies

Entity Relationship Modelling


Entities
• Entities represent • Entities have
objects or things of • A general type or
interest class, such as
• Physical things like Lecturer or Module
students, lecturers, • Instances of that
employees, products particular type, such
• More abstract things as Steve Mills,
like modules, orders, Natasha Alechina are
courses, projects instances of Lecturer
• Attributes (such as
name, email address)

Entity Relationship Modelling


Diagramming Entities
• In an E/R Diagram, Lecturer ID

an entity is usually Name Course


drawn as a box with
rounded corners
Tutors Student
• The box is labelled
with the name of the
class of objects
represented by that Module Studies
entity

Entity Relationship Modelling


Attributes
• Attributes are facts, • Attributes have
aspects, properties, • A name
or details about an • An associated entity
entity • Domains of possible
• Students have IDs, values
names, courses, • Values from the
addresses, … domain for each
• Modules have codes, instance of the entity
titles, credit weights, they are belong to
levels, …

Entity Relationship Modelling


Diagramming Attributes
• In an E/R Diagram Lecturer ID

attributes may be Name Course


drawn as ovals
• Each attribute is
Tutors Student
linked to its entity by
a line
• The name of the
attribute is written in Module Studies
the oval

Entity Relationship Modelling


Relationships
• Relationships are an • Relationships have
association between • A name
two or more entities • A set of entities that
• Each Student takes participate in them
several Modules • A degree - the
• Each Module is taught number of entities
by a Lecturer that participate (most
• Each Employee works have degree 2)
for a single • A cardinality ratio
Department

Entity Relationship Modelling


Cardinality Ratios
• Each entity in a • One to one (1:1)
relationship can • Each lecturer has a
unique office
participate in zero,
• One to many (1:M)
one, or more than • A lecturer may tutor
one instances of that many students, but each
relationship student has just one
tutor
• This leads to 3 types • Many to many (M:M)
of relationship… • Each student takes
several modules, and
each module is taken by
several students

Entity Relationship Modelling


Diagramming Relationships
• Relationships are Lecturer ID

links between two Name Course


entities
• The name is given in
Tutors Student
a diamond box
• The ends of the link
show cardinality
Module Studies

One Many

Entity Relationship Modelling


Removing M:M Relationships
• Many to many Student
relationships are
difficult to represent Student
Has
• We can split a many
to many relationship
Studies Enrolment
into two one to many
relationships
In
• An entity represents Module
the M:M relationship
Module

Entity Relationship Modelling


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

Entity Relationship Modelling


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

Entity Relationship 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

Entity Relationship 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

Entity Relationship Modelling


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

Course Module Lecturer

Student

Entity Relationship Modelling


Example - E/R Diagram
Each department offers several courses
Offers Department

Course Module Lecturer

Student

Entity Relationship Modelling


Example - E/R Diagram
A number of modules make up each courses
Offers Department

Course Includes Module Lecturer

Student

Entity Relationship Modelling


Example - E/R Diagram
Students enrol in a particular course
Offers Department

Course Includes Module Lecturer

Enrols In Student

Entity Relationship Modelling


Example - E/R Diagram
Students … take modules
Offers Department

Course Includes Module Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


Example - E/R Diagram
Each module is taught by a lecturer
Offers Department

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


Example - E/R Diagram
a lecturer from the appropriate department
Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


Example - E/R Diagram
each lecturer tutors a group of students
Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

Entity Relationship Modelling


Example - E/R Diagram

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

Entity Relationship Modelling


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

Entity Relationship Modelling


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.

Entity Relationship Modelling


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

Entity Relationship Modelling


Example - E/R Diagram
Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

Entity Relationship Modelling


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

Entity Relationship Modelling


Example - E/R Diagram
Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

Entity Relationship Modelling


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

Entity Relationship Modelling


Redundant Relationships
• We can merge the a x

two entities that take


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

c z

Entity Relationship Modelling


Example - E/R Diagram
Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

Entity Relationship Modelling


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

Entity Relationship Modelling


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

Entity Relationship Modelling


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

Has

ID
(2) Find instances of the Enrolment entity
Enrolment
Code with the same Code as the result of (1)

In

Code
(1) Find the instance of the Module
Module
Title entity with title ‘Database Systems’
Entity Relationship Modelling

You might also like