Sie sind auf Seite 1von 48

INT306

Database Management Systems


LECTURE4
‘ LET’S MOVE TOWARD THE BETTER WAY TO STOREAND
MANAGE THE DATA’
Entity/Relationship
Modelling
COURSE WORK

STUDENT DOES
Database Design
Before we look at how to Conceptual design
create and use a database ◦ Build a model independent of
we’ll look at how to design the choice of DBMS
one Logical design
Need to consider ◦ Create the database in agiven
◦ What tables, keys, and DBMS
constraints are needed?
Physical design
◦ What is the database goingto
◦ How the database is storedin
be used for?
hardware

ENTITY RELATIONSHIPMODELLING
Entity/Relationship Modelling
E/R Modelling is used for Example
conceptual design ◦ In a University database we might
◦ Entities - objects or itemsof have entities for Students,
interest Modules and Lecturers. Students
◦ Attributes - facts about,or might have attributes such as their
properties of, an entity ID, Name, and Course, and could
have relationships with Modules
◦ Relationships - links between
(enrolment) and Lecturers
entities (tutor/tutee)

ENTITY RELATIONSHIPMODELLING
Entity/Relationship Diagrams
E/R Models are often ID
Lecturer
represented as E/R diagrams
that Name Course
◦ Give a conceptual view of the
database
◦ Are independent of the choice Tutors Student
of DBMS
◦ Can identify some problems in a
design
Module Studies

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

ENTITY RELATIONSHIPMODELLING
Weak and Strong Entity
A weak entity is an entity that depends on the existence of another entity.
In more technical terms it can defined as an entity that cannot be identified
by its own attributes.

It uses a foreign key combined with its attributed to form the primary key.

An entity like order item is a good example for this.

The order item will be meaningless without an order so it depends on the


existence of order.
Weak and Strong Entity
Weak and Strong Entity
An entity set that has a primary key is called as Strong entity set.

Consider an entity set Payment which has three attributes:


payment_number, payment_date and payment_amount.

Although each payment entity is distinct but payment for different loans
may share the same payment number. Thus, this entity set does not
have a primary key and it is an entity set
Weak and Strong Entity
Aweak entity set does not have a primary key but we need a means of
distinguishing among all those entries in the entity set that depend on
one particular strong entity set.

The discriminator of a weak entity set is a set of attributes thatallows


this distinction be made.

For example, payment_number acts asdiscriminator for payment entity


set.
Weak and Strong Entity
A member of a strong entity set is called dominant entity andmember
of weak entity set is called as subordinateentity.
Weak and Strong Entity
Notations in ERdiagram

ENTITY RELATIONSHIPMODELLING
Diagramming Entities
In an E/R Diagram, an entity ID
Lecturer
is usually drawn as a box
with rounded corners Name Course

The box is labelled with the


name of the class of objects Tutors Student
represented by that entity

Module Studies

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

ENTITY RELATIONSHIPMODELLING
Types of Attributes
Simple attribute − Simple attributes are atomic values, which cannot be divided
further. For example, a student's phone number is an atomic value of 10 digits.

Composite attribute − Composite attributes are made of more than one simple
attribute. For example, a student's complete name may have first_name and
last_name.

Derived attribute − Derived attributes are the attributes that do not exist in the
physical database, but their values are derived from other attributes present in the
database.

For example, average_salary in a department should not be saved directly in the


database, instead it can be derived. For another example, age can be derived from
data_of_birth.
Types of Attributes
Single-value attribute − Single-value attributes contain single value.

For example − Social_Security_Number.

Multi-value attribute − Multi-value attributesmay contain more than


one values.

For example, a person can have more than one phone number,
email_address, etc.
Diagramming Attributes
In an E/R Diagram attributes ID
Lecturer
may be drawn as ovals
Name Course
Each attribute is linked to its
entity by aline
The name of the attribute is Tutors Student
written in the oval

Module Studies

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

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

ENTITY RELATIONSHIPMODELLING
Diagramming Relationships
Relationships are links ID
Lecturer
between two entities
Name Course
The name is given in a
diamond box
The ends of the link show Tutors Student
cardinality

Module Studies

One Many

ENTITY RELATIONSHIPMODELLING
Removing M:M Relationships
Many to manyrelationships
are difficult to represent Student

We can split a many to many Student


relationship into two one to Has
many relationships
An entity represents the Studies Enrolment
M:M relationship
In
Module

Module

ENTITY RELATIONSHIPMODELLING
Making E/RModels
Tomake an E/R model you General guidelines
need to identify ◦ Since entities are things or
◦ Enitities objects they are often nounsin
◦ Attributes the description
◦ Relationships ◦ Attributes are facts or
properties, and so are often
◦ Cardinality ratios nouns also
from adescription ◦ Verbs often describe
relationships between entities

ENTITY RELATIONSHIPMODELLING
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 RELATIONSHIPMODELLING
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 RELATIONSHIPMODELLING
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 fromthe
appropriate department, and each lecturer tutors a group
of students

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Entities: Department, Course, Module, Lecturer, Student

Department

Course Module Lecturer

Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Each department offers several courses

Offers Department

Course Module Lecturer

Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
A number of modules make up each courses

Offers Department

Course Includes Module Lecturer

Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Students enrol in a particular course

Offers Department

Course Includes Module Lecturer

Enrols In Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Students … take modules

Offers Department

Course Includes Module Lecturer

Takes

Enrols In Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Each module is taught by a lecturer

Offers Department

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
a lecturer from the appropriate department

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
each lecturer tutors a group of students

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

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

ENTITY RELATIONSHIPMODELLING
Example
We want torepresent 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 RELATIONSHIPMODELLING
Example - Entities/Attributes
Entities or attributes: Products, suppliers, and
◦ product addresses all have smaller
◦ description parts so we can make them
◦ price entities
◦ supplier
◦ address
The others have no smaller
◦ phone number
parts and belong to a single
◦ name entity
◦ street address
◦ city
◦ postcode

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

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

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

ENTITY RELATIONSHIPMODELLING
One to OneRelationships
Some relationships between Example - the supplier-
entities, A and B, might be address relationship
redundant if ◦ Is one to one
◦ It is a 1:1 relationshipbetween ◦ Every supplier has an address
A and B ◦ We don’t need addressesthat
◦ Every A is related to a Band are not related to asupplier
every B is related to anA

ENTITY RELATIONSHIPMODELLING
Redundant Relationships
We can merge the two a x
entities that take part in a
redundant relationship b A B y
together
◦ They become a single entity c z
◦ The new entity has all the
attributes of the oldone
a x

b AB y

c z

ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

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

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

Module

ENTITY RELATIONSHIPMODELLING
Debugging Designs
ID (3) For each instance of Enrolment in the
Student 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
ENTITY RELATIONSHIPMODELLING
TASK
“A database will be made to store informationabout
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 giventime.”
ENTITY RELATIONSHIPMODELLING

Das könnte Ihnen auch gefallen