Beruflich Dokumente
Kultur Dokumente
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.
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.
ENTITY RELATIONSHIPMODELLING
Diagramming Entities
In an E/R Diagram, an entity ID
Lecturer
is usually drawn as a box
with rounded corners Name Course
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, 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
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
Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Each department offers several courses
Offers Department
Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
A number of modules make up each courses
Offers Department
Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Students enrol in a particular course
Offers Department
Enrols In Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Students … take modules
Offers Department
Takes
Enrols In Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Each module is taught by a lecturer
Offers Department
Takes
Enrols In Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
a lecturer from the appropriate department
Takes
Enrols In Student
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
each lecturer tutors a group of students
Takes
ENTITY RELATIONSHIPMODELLING
Example - E/RDiagram
Offers Department Employs
Takes
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
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
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
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
In