0% found this document useful (0 votes)
6 views

Introduction to Databases Full Module

The document outlines a course on database models and design, emphasizing the importance of databases in business and daily life. It covers key concepts such as the definition of a database, types of database systems, advantages and disadvantages of using databases, and the components of a Database Management System (DBMS). Additionally, it discusses data independence and various data models, including hierarchical and network models.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Introduction to Databases Full Module

The document outlines a course on database models and design, emphasizing the importance of databases in business and daily life. It covers key concepts such as the definition of a database, types of database systems, advantages and disadvantages of using databases, and the components of a Database Management System (DBMS). Additionally, it discusses data independence and various data models, including hierarchical and network models.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 215

IT203: Models Of Database &

Database Design

Lecturer: Mrs. ET. Chigodo


email : [email protected]
Cell : 0773 280408

1.Bsc (Hons) Business Management & IT


2.Msc Information Systems Management (MSU)
COURSE OBJECTIVES
• To understand the importance of a database in business.
• To differentiate a database from the traditional file
based approach.
• To distinguish between at least three types databases
models
• To describe the three schema architecture.
• To define database terms and components.
• To demonstrate an understanding of normalization.
• To have an understanding of the database life cycle.
• To design a simple database.
• To have an understanding of how to secure a database.
WHY STUDY DATABASES??

MOTIVATION 1

We live in a database world!!!


•Iused a telephone. When you use a telephone, all the
details about the call are stored in a database.
• Call length, what number you called, time of call, billing
information, and so on. Cell phone databases are even
more complex.
WHY STUDY DATABASES??

MOTIVATION 2
• I paid by credit card. Huge databases are involved.
• Every time somebody runs your credit card through a swipe reader
or types in the number, they're checking information in a database.
• Is this a valid credit account?
• Does it have enough money to cover the bill?
• Is the credit card stolen?
• Debit the merchant account, credit the consumer account

• Whether the transaction is accepted or rejected, all the details are


recorded in a database somewhere.
MORE MOTIVATION
• Every time you go to an ATM, use a credit card, buy something with a
UPC bar code at a supermarket or department store, go to a movie,
concert, or Caps game, register for classes, or get a parking ticket in Lot
4, you are working with databases.
• Everything in your wallet that isn't a photograph is an entry in a
database somewhere
• medical plan cards
• credit cards
• student ID
• driver's license
• membership cards in clubs or interest groups
• everything. Even the currency!
OTHER EXAMPLES OF DATABASES

Some examples of databases you may encounter in your


daily life are:

• Banking: all transactions


• Airlines: reservations, schedules
• Universities: registration, grades
• Sales: customers, products, purchases
• Manufacturing: production, inventory, orders, supply chain
• Human resources: employee records, salaries, tax
deductions

Databases are intertwined in our


lives
FINAL MOTIVATION
• Databases are all around us.

• Knowledge is power.
• Databases give us power (the ability to do things we couldn’t
otherwise do)
• they give other people power over us, and knowledge about
what we are doing.
• This class is about Databases.

So what is a Database?
CONT.
• Before we start with the use and architecture of data
management solutions we discuss the terminology of this
field to get to know the basic terms like information, data,
and database systems.
• A lot of these basic terms are used daily but most often not
in the right context.
• Data refers to raw facts & figures which are not processed
,which do not have any meaning and therefore cannot be
used for decision making.
• Information
is processed data which has meaning ,context,
relevance and purpose & can now be used for decision
making.
Introduction To
Databases
DATABASE

Definition:
It is a shared collection of logically interrelated data designed
to meet the varied information needs of an organisation.
A collection of interrelated data items that are managed as a
single unit.
The primary aim of database is to provide a way to store and
retrieve database information in fast and efficient manner.
BASIC TERMS IN DATABASE
Entity -a person, thing, place, or event for which data is collected.
Attribute/ a property of an entity.
Tuple: Is a row—record.
A record-one piece of data, i.e., one student's information, a recipe,
a test question.
Relationship -association between entities.
Primary Key- a field that uniquely identifies a record. no duplicate
entries are allowed for the field serving this role.
A field-one category of information, i.e., Name, Address, Semester
Grade, Academic topic.
Metadata-data that describe properties/characteristics of other
data. Include data definitions/types, data structures, and rules
or constraints.
Traditional File System Database System
Weak data integrity- Integrity Better data integrity
constraints .Hard to add new
constraints or change existing
ones
Data redundancy & No data redundancy
inconsistency . Multiple file
formats, duplication of
information in different files
Data sharing is not possible Data sharing is possible
Difficulty in accessing data - indexed and searchable
Need to write a new program to
carry out each new task
File-based system consists of A database management
multiple, often unrelated files. system often puts data
into tables.
Traditional File Approach is Database are data
data dependence independence
Cont….

Non-concurrency Concurrent access by


multiple users-
Uncontrolled concurrent
accesses can lead to
inconsistencies. E.g. two
people reading a balance
and updating it at the
same time.

Less secure More secure - use of


passwords
SUMMARY
ADVANTAGES OF DATABASES

• Reduced data redundancy.


• Reduced updating errors and increased consistency.
• Greater data integrity and independence from
applications programs.
• Improved data access to users through use of host and
query languages.
• Improved data security
DISADVANTAGES

• Database systems are complex, difficult, and time-


consuming to design.
• Substantial hardware and software start-up costs.
• Damage to database affects virtually all applications
programs.
• Extensive conversion costs in moving form a file-based
system to a database system.
• Initial training required for all programmers and
users.
DATABASE MANAGEMENT SYSTEM (DBMS)

• Itis a software system that enables users to define,


create, expand and maintain the database and
provides controlled access to the database by use of
passwords.
• Itis the software that interacts with the user’s
application programs and the database.
COMPONENTS OF THE DBMS
• Data Dictionary - this is a database management tool that has
names and descriptions of all data elements within a
database.
• Data languages- To place a data element into the Data
Dictionary, a special language is used to describe the
characteristics of the data element. This language is called a
Data Definition Language or DDL. There is also a Data
Manipulation Language(DML) which of consists of a series of
commands such as FIND, GET, to help retrieve data from the DB.
• Security Software- This is a set of software used to minimize
unauthorized access to the database.
• Archiving and Recovery Systems - these systems are used to
store backups of the original record so that if the original
database is damaged the information can still be recovered.
COMPONENTS OF THE DBMS

• Report Writers - These allow the user to obtain reports from


the data quicker and easier.

• Teleprocessing Monitor - This is a software that controls


and manages the communication between remote terminals e.g.
from and to sales points in a large departmental store
FUNCTIONS OF THE DBMS
Data storage, retrieval & update.
• This is the fundamental function of a DBMS. A DBMS must furnish users
with the ability to store, retrieve and update data in the database.

A user-accessible catalog.
• A DBMS must furnish a catalog in which descriptions of data items are
stored & which is accessible to users.

Transaction Support.
• A DBMS must furnish a mechanism which will ensure either that all the
updates corresponding to a given transaction are made or that none of
them is made.

Concurrency control services.


• A DBMS must furnish a mechanism to ensure that the database is
updated correctly when multiple users are updating the DB correctly.
FUNCTIONS OF THE DBMS

Recovery services.
• A DBMS must furnish a mechanism for recovering the database in the
event that the database is damaged in any way.

Authorization services.
• A DBMS must furnish a mechanism to ensure that only authorized users can
access the database.

Integrity services.
A DBMS must furnish a mechanism a means to ensure that both the data in
the DB and changes to the data follow certain rules.
THE DATABASE ENVIRONMENT:
COMPONENTS OF THE DBMS ENVIRONMENT

• The DBMS requires a certain environment with certain


components for it to run successfully .
• There are five (5) major components of the DBMS
environment namely:
• Hardware
• Software
• Data
• Procedure
• People
COMPONENTS OF DBMS
ENVIRONMENT
COMPONENTS OF DBMS ENVIRONMENT
Hardware
• The DBMS and applications require Hardware to run.
• The hardware ranges from a single personal computer to the
mainframe to the network computer. The particular depends on
the organisation’s requirements and the DBMS used.

Software
• A software component comprises the DBMS software itself and the
application programs together with the operating system including
network software if the DBMS is being used over and over again.

Data
• This is the most important component of the DBMS environment from
the end user’s point of view. It acts as a bridge between the
machine components and the human components.
COMPONENTS OF DBMS ENVIRONMENT
Procedures
• These refer to the instructions that govern the design and use of
the database. The users of the system and the staff that
manages the database require documented procedures on how
to use or run the system.

People
• There are four (4) distinct types of people that participate in the
DBMS environment.
• Data and Database administrators
• Database designers
• Application Programmers
• End users
COMPONENTS OF DBMS ENVIRONMENT
Data and Database administrators.
• These are responsible for the management of the data resources
including planning, development and maintenance of standards,
policies and procedures and conceptual or logical database
design.
Database Designers.
• These are concerned with identifying the data (entities and
attributes), the relationships between the data and the
constraints on the data that is to be stored in the database.
Application Programmers.
• Once the database has been implemented, the application
programs that provide the required functionality for the end
users must be implemented and this is the responsibility of the
application programmer.
COMPONENTS OF DBMS ENVIRONMENT
End Users.

• These are the clients for the database. They are classified
as:
Naïve Users
• These are typically unaware of the DBMS. They access the
database through specially written application programs
which attempt to make the operation as simple as
possible.
Sophisticated Users
• Are familiar with the structure of the database and the
facilities offered by the DBMS. These may use a high level
query language such as SQL to perform the required
operations.
DATABASE CONCEPTS AND ARCHITECTURE

• Database architecture: Three schema Architecture.


• Data Models.
DATABASE ARCHITECTURE AND DATA INDEPENDENCE
• The goal of the three schema architecture is to separate the
users, applications and the physical database.

• There are several reasons why this separation is desirable:


a. Each user should be able to access the same data, but have a
different customized view of the data. Each user should be able
to change the way he or she views the data, and this change
should not affect other users.
b. Users should not have to deal directly with physical database
storage details, such as indexing or hashing .In other words, a
user’s interaction with the database should be independent of
storage considerations.
c. The Database Administrator (DBA) should be able to change the
database storage structures without affecting the users’ views.
d. The internal structure of the database should be unaffected by
changes to the physical aspects of storage.
ANSI-SPARC
THREE-LEVEL ARCHITECTURE
ANSI-SPARC THREE-LEVEL ARCHITECTURE
EXTERNAL LEVEL.
The users’ view of the database. This level describes that part of the level
database that is relevant to each user hides the rest of the
database from that user group.
CONCEPTUAL LEVEL.
The community view of the database. This level describes what data level
is stored in the database and the relationships among the data.
It hides the details of physical storage structures and concentrates on
describing entities, data types, relationships, user operations and
constraints.
INTERNAL LEVEL.
The physical representation of the database on the computer. This level
describes how the data is stored in the database. It uses the physical
data model and describes the complete details of data storage and
access parts for the database.
DIFFERENCES BETWEEN THREE LEVELS OF
ANSI-SPARC ARCHITECTURE
DATA INDEPENDENCE
• A major objective for the three-level architecture is to
provide data independence, which means that upper
levels are unaffected by changes to lower levels.
• This is defined as the capacity
to change the schema at
one level of the database system without having to
change the schema at the next higher level.
Two types of data independence can be defined which
are:
• Logical data independence.
• Physical data independence.
LOGICAL DATA INDEPENDENCE.

• Logicaldata independence refers to the immunity of


the external schemas to changes in the conceptual
schema.
• Changes to the conceptual schema, such as the addition
or removal of new entities, attributes, or relationships,
should be possible without having to change existing
external schemas or having to rewrite application
programs.
• Clearly, the users for whom the changes have been
made need to be aware of them, but what is important
is that other users should not be.
PHYSICAL DATA INDEPENDENCE
• Physical data independence refers to the immunity of
the conceptual schema to changes in the internal
schema.
• Changes to the internal schema, such as using
different file organizations or storage structures,
using different storage devices, modifying indexes, or
hashing algorithms, should be possible without having
to change the conceptual or external schemas.
DATA INDEPENDENCE AND THE ANSI-
SPARC THREE-LEVEL ARCHITECTURE.
DATA MODELS
• An understanding of data models is very important in
the study of databases.
• If we want to design a database, we need to know
the different layers that we can have in a database.
• A data model is a collection of concepts and rules for
the description of the structure of the database.
• Data models can be categorised according to the
type of concepts used to describe the database
function.
DATA MODELS
Data models fall into two broad categories as below:
1.Object based data models
2.Record based data models
Object based data model.
• These are used to describe data that is in the conceptual
and external levels. They use concepts such as entities,
attributes and relationships.
Record based data model.
There are three principal types of record based logical
data models namely:
• Relational data model
• Network data model
• Hierarchical data model
THE HIERARCHICAL MODEL
• Similar to an organisational chart
• Think of the way we structure our personal
computer files into directories and subdirectories
and files.
HIERARCHICAL MODEL
• Parent-child
relationship also known
as the ‘one-to-many
relationship’.
• One parent can have
many children.
• Each child can only
have one parent.
• (eg a manager is
responsible for many
employees but each
employee has only one
manager).
HIERARCHICAL DATABASE MODEL

Advantages
• Conceptual simplicity
• Database security and integrity
• Data independence
• Efficiency

Disadvantages
• Complex implementation
• Difficult to manage and lack of standards
• Lacks structural independence
• Applications programming and use complexity
NETWORK DATABASE MODEL
• Each record can have multiple parents
• Composed of sets - relationships
• Each set has owner record and member record
• Member may have several owners
• A set represents a 1:M relationship between the
owner and the member
• Main difference between these models-network model
may include a condition in which a member can have
several owners.

• It is built on the concept of multiple branches


emanating from one or more nodes.

• Network model branches can be connected to multiple


nodes.

• Able to represent redundancy in data more efficiently


than in the hierarchical model.
NETWORK DATABASE MODEL
• Advantages
• Conceptual simplicity
• Handles more relationship types
• Data access flexibility
• Promotes database integrity
• Data independence
• Conformance to standards

• Disadvantages
• System complexity
• Lack of structural independence
RELATIONAL MODEL

• The relational model is the best known and is today’s


DBMS most often implemented database model.

• It defines a database as a collection of tables


(relations) which contain all data.
RELATIONAL DATABASE MODEL
• Perceived by users as a collection of tables
for data storage.

• Tables are a series of row/column


intersections (a row corresponds to a record, a
column to a field).

•A relation is a table with columns and rows


and tables related by sharing common entity
characteristic(s).
45
RELATIONAL DATABASE
RELATIONAL DATABASE MODEL

• Advantages
• Structural independence
• Improved conceptual simplicity
• Easier database design, implementation,
management, and use
• Ad hoc/improvised query capability with
SQL
RELATIONAL DATABASE MODEL

• Disadvantages
• Substantial hardware and system software
overhead
• Poor design and implementation is made
easy
• May promote “islands of information”
problems
OBJECT-RELATIONAL MODEL
• Object-oriented models are very powerful but also quite
complex.
 These allow us to work with the widely known relational
database model but also have some advantages of the
object-oriented model without its complexity.
 The goal of the model is to define objects that can be
reused in many programs in order to save time and reduce
errors.
 The objects have three components: name, set of properties
or attributes, and methods or functions.
DATABASE LIFE CYCLE
DATABASE LIFE CYCLE
• A database system is a fundamental component of an organization’s
information systems.
• Information systems refer to the resources that enable a collection,
management, control and dissemination of the information throughout
an organization.

• A database life cycle is managed by the Database Administrator . It


consists of the following stages.
1.Planning
2.Requirements Formulation & Analysis
3.Design
4.Implementation
5.Operation & Maintenance
6.Growth & Change
DATABASE LIFE CYCLE

1.Planning

2. Requirements
6. Growth & Formulation &
Change Analysis

5.Operation &
maintenance 3.Design

4.Implementation
DATABASE LIFE CYCLE
1.Planning:
• Its purpose is to develop a strategic plan for database development that
supports the overall organisation business plan. Database planning has
three main components which are shown below:
• Work to be done
• Resources with which to do it 5 Ms - minutes, money, machinery, materials, manpower

• Money to be paid for it all


2.Requirements Formulation & Analysis
• Is concerned with identifying data elements currently used by the
organisation, precisely defining these elements & their relationship, and
documenting the results in a form that is convenient to the design that is to
follow.
• In addition to identifying current data, requirements formulation &
analysis attempts to identify new data elements or changes in existing
data elements that will be required in the near future.
DATABASE LIFE CYCLE
3. Design Stage
• Its purpose is to develop a database architecture that will meet the
information needs of the organization now and in the future.
• There are 3 stages in database design, that is, Conceptual,
Implementation & Physical design.
• Conceptual Design: Its purpose is to synthesize the various user views
and information requirements into a global database design. The
Conceptual Data Model describes entities, attributes and relationships
(ERDs).
• Implementation Design: Its purpose is to map the Conceptual Data
Model into a logical schema that can be processed by a particular
DBMS. The conceptual data model is mapped into hierarchical, network
or relational data model.
• Physical Design: Last stage of Database design concerned with
designing stored record formats, selecting access methods and deciding
on physical factors such as record blocking.
DATABASE LIFE CYCLE
4. Implementation Stage:
• Once the database is completed, the implementation process
begins. The first step is the creation or initial load of the
database.
• Database administration manages the loading process and
resolves any inconsistencies that arise during this process.
5. Operation & Maintenance Stage
• This is the ongoing process of updating the database to keep it
current.
• Examples of updating include adding a new employee record,
changing a student address, deleting an invoice. Database
Administrator is responsible for developing procedures that
ensure that the database is kept current and that is protected
during update operations
DATABASE LIFE CYCLE
6.Growth and Change Stage
• The database is a model of the organisation itself.
• As a result it is not static but reflects dynamic changes in the
organisation and its environment.
• The Database Administrator must plan for change, monitor the
performance of the database both efficiency and user satisfaction,
and take whatever action are required to maintain a high level of
system performance and success.
ENTITY RELATIONSHIP DIAGRAMS (ERDS)
ENTITY RELATIONSHIP DIAGRAM

• Entities are real world objects, tangible or intangible on which we store


data.
• For example on a student database we have a student as an entity who
has attributes like name, sex, age ,program among other things.
• However, as you have seen, a student does not act as a standalone
entity, but instead exists with other entities such as lecturer, librarian,
dean, etc.
• This thereby brings out the need to establish relationships that exist
between entities when we want to create a database.
• This unit takes us through the steps that are followed in the development
of an entity relationship diagram.
ENTITY RELATIONSHIP DIAGRAMS

Entity-Relationship Diagram (ERD) is a graphical


representation of a Entity-Relationship Model .

Entity-Relationship Model (ERM) is a detailed,


logical representation of the data for an
organization or for a business area.

Expressed in terms of:


• Entities
• Attributes
• Relationships
ENTITY RELATIONSHIP DIAGRAMS
An entity is a business object that represents a group,
or category of data.

An attribute is a sub-group of information within an


entity or is a property or characteristic of an entity
that is of interest to the organization”

Relationships are associations between one or more


entity types.
They are the “glue” that holds together components
of an E-R model.
ENTITY/RELATIONSHIP MODELLING
• E/R Modelling is used for conceptual design
• Entities - objects or items of interest
• Attributes - facts about, or properties of, an entity
• Relationships - links between entities
Example:

In a University database we might have entities for Students,


Modules and Lecturers. Students might have attributes such
as their ID, Name, and Course, and could have relationships
with Modules (enrolment) and Lecturers (tutor/tutee)
ENTITY/RELATIONSHIP DIAGRAMS

Lecturer ID

Name Course

Tutors Student

Module Studies
DIAGRAMMING ENTITIES

• In an E/R Diagram, an entity Lecturer ID

is usually drawn as a box Name Course

with rounded corners


• The box is labelled with the Tutors Student

name of the class of objects


represented by that entity
Module Studies

Entity Relationship
Modelling
ATTRIBUTES

• Attributes are facts, aspects, properties, or details


about an entity

• Students have IDs, names, courses, addresses, …

• Modules have codes, titles, credit weights, levels, …

Entity Relationship
Modelling
DIAGRAMMING ATTRIBUTES
• In an E/R Diagram ID
Lecturer
attributes may be drawn as
Name Course
ovals
• Each attribute is linked to its Tutors Student
entity by a line
• The name of the attribute is
written in the oval Module Studies

Entity Relationship
Modelling
RELATIONSHIPS

• Relationships are an association between two or


more entities

• Each Student takes several Modules


• Each Module is taught by a Lecturer
• Each Employee works for a single 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, or
• One to many (1:M)
more than one instances of
• A lecturer may tutor
that relationship many students, but
each student has just
one tutor
• This leads to 3 types of • Many to many (M:M)
relationships… • Each student takes
several modules, and
each module is taken
Entity Relationship by several students
Modelling
DIAGRAMMING RELATIONSHIPS
Lecturer ID
• Relationships are links Name Course
between two entities
• The name is given in a Tutors Student
diamond box
• The ends of the link show
cardinality Module Studies

One Many

Entity Relationship
Modelling
MAKING E/R MODELS
• To make an E/R model you need to identify
• Entities
• Attributes
• Relationships
• Cardinality ratios
• General guidelines
• Since entities are things or objects they are often nouns in
the description
• Attributes are facts or properties, and so are often nouns
also
• Verbs often describe relationships between entities
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
EXAMPLE 2

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 - E/R DIAGRAM
Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

Entity Relationship
Modelling
EXCELLENCE TRANSPORT P/L owns a number of busses. Each bus is allocated to
a particular route, although some routes may have several busses. Each route
passes through a number of towns. One or more drivers are allocated to each
stage of a route, which corresponds to a journey through some or all of the
towns on a route. Some of the towns have a garage where busses are kept and
each of the busses are identified by the registration number and can carry
different numbers of passengers, since the vehicles vary in size and can be single
or double-decked. Each route is identified by a route number and information is
available on the average number of passengers carried per day for each route.
Drivers have an employee number, name, address, and sometimes a telephone
number.

QUESTION
Draw an E-R diagram for Excellence Transport P/L using the information
given above.
ASSIGNMENT

• Draw an E-R Diagram for the following scenario:


A commercial bakery makes many different products. These include
bread, deserts, special cakes and many other baked goods.
Ingredients such as flour , spices, milk and so on are purchased from
vendors. Sometimes an ingredient is purchased from a single vendor
and other times an ingredient is purchased from many vendors. The
bakery has commercial customers , such as schools ad restaurants
that regularly place orders for baked goods. Each baked good has a
specialist that oversees the setup of the bake operation and inspects
the finished product.
NORMALIZATION

• Types of normal forms: 1NF, 2NF, 3NF, BCNF, and 4NF


NORMALIZATION
• If you remember quite well, one of the problems with
traditional filing was data redundancy.

• The introduction of databases may have come as a solution but


it is only a solution if the database is properly designed,
otherwise the problem will continue to manifest.

• This unit introduces us to the concept called normalisation which


takes a relation from one level to another in order to facilitate
easy storage and retrieval of data.
NORMALISATION

• Database normalisation is the process of organizing the


columns (attributes) and tables (relations) of a relational
database to minimize data redundancy.

There are two major goals of the normalization process:


• eliminating
redundant data (for example, storing the same
data in more than one table)
• ensuring data dependencies make sense (only storing related
data in a table)
NORMALISATION

• If a database design is not perfect


(normalised), it may contain anomalies:

i. Update anomalies
ii. Deletion anomalies
iii. Insert anomalies
UPDATE ANOMALIES
• If data items are scattered and are not linked to
each other properly, then it could lead to strange
situations.

• For example, when we try to update one data item


having its copies scattered over several places, a few
instances get updated properly while a few others
are left with old values.

• Such instances leave the database in an inconsistent


state.
DELETION & INSERTION ANOMALIES

Deletion anomalies
• We tried to delete a record, but parts of it was left
undeleted because of unawareness, the data is also
saved somewhere else.
Insert anomalies
• We tried to insert data in a record that does not
exist at all.
THREE STEPS OF DATA NORMALIZATION

User View

Unnormalized
Relationship
Remove repeating groups
Normalized
Relations (1NF)
Remove partial dependencies
Second Normal Form
Relations (2NF)
Remove transitive dependencies
Third Normal Form
Relations (3NF)
92
THREE STEPS OF DATA NORMALIZATION
FIRST NORMAL FORM (1NF)
• Firstnormal form (1NF) sets the very basic rules
for an organized database:

• Eliminate duplicative columns from the same table


or remove multiple values in a column.

• Create separate tables for each group of related


data and identify each row with a unique column
or set of columns (the primary key).
FIRST NORMAL FORM

• We re-arrange the relation (table) as below to


convert it to First Normal Form.
SECOND NORMAL FORM
• A table is said to be in 2NF if both the following
conditions hold:

The table should be in the First Normal Form.


• The table should satisfy all the rules for the 1NF
There should be no Partial Dependency.
Every non-key attribute is fully functionally dependent
on the primary key or each non-key attribute needs
the full primary key to be uniquely identified.
• In 2NF, the main objective is to remove partial
dependency,
SECOND NORMAL FORM

Example:
• Suppose a school wants to store the data of
teachers and the subjects they teach. They create
a table that looks like this:
• Since a teacher can teach more than one
subjects, the table can have multiple rows for a
same teacher.
teacher_id subject teacher_age

111 Maths 38

111 Physics 38

222 Biology 38

333 Physics 40

333 Chemistry 40
2ND NORMAL FORM
• The table is in 1NF because each attribute has
atomic values. However, it is not in 2NF because
non prime attribute teacher s age and subject is
dependent on teacher_id alone which is a
proper subset of candidate key. This violates the
rule for 2NF as the rule says “no non-prime
attribute is dependent on the proper subset of
any candidate key of the table”.
• To make the table complies with 2NF we can
break it in two tables like this:
teacher details table

teacher_id teacher_age

111 38

222 38

333 40
teacher subject table:

teacher_id subject

111 Maths

111 Physics

222 Biology

333 Physics

333 Chemistry
THIRD NORMAL FORM

• The major objective of the 3NF is to remove


transitive dependency.
Third Normal Form (3NF)
This form dictates that all non-key
attributes of a table must be
functionally dependent on a
candidate key i.e. there can be no
interdependencies among non-key
attributes.
For a table to be in 3NF, there are two
requirements
• The table should conform to second normal
form
• No attribute is transitively dependent on the
primary key
Third Normal Form (3NF)

1. Move all items involved in


transitive dependencies to a new
entity.
2. Identify a primary key for the
new entity.
3. Place the primary key for the new
entity as a foreign key on the
original entity.
Third Normal Form (3NF)
BOYCE CODD NORMAL FORM (BCNF)

• It is a stronger version of 3NF whose objective is to


address anomalies of the 3NF.
• It is sometimes called 3,5NF.
RULES FOR BCNF
• Database Should be in 3NF mode.
• There should be NO Trivial dependencies.
EXAMPLES OF TRIVIAL DEPENDENCIES IN A
SUPERMARKET ENVIRONMENT

• Each invoice can have many items


• Each supplier can supply one type of item on several
invoices
• Each type of item can have several different
suppliers
• Each supplier can supply only one item
• Each item can have several suppliers
SUPPOSE WE HAVE A 3NF TABLE BELOW:

Invoice # Item Supplier

001 SURF UNILEVER

001 POLONY COLCOM

003 CAFENOL CAPS

004 Roller meal SILO

004 KIWI Datlabs

005 TYRE WAX SHIELD


INVOICE# AS PRIMARY KEY IS NOT ENOUGH

• We introduce an attribute Supplier as our foreign key


and we end up having two tables linked with foreign
key as given below:
INTRODUCING A SUPPLIER FOREIGN KEY FOR
THE TWO TABLES

Invoice # Supplier Supplier Item


001 UNILEVER UNILEVER SURF
001 COLCOM COLCOM POLONY

003 CAPS CAPS CAFENOL

004 SILO SILO CHIBATAURA

004 Datlabs Datlabs KIWI


005 SHIELD SHIELD TYRE WAX
TABLE IS NOW IN BCNF
DATABASE LANGUAGES:
RELATIONAL ALGEBRA

• Relational algebra from set theory


• Unary relational operations
• Binary relational operations
• Additional relational operations
INTRODUCTION

• Database languages are used for read,


update and store data in a database. e.g.
Structured Query Language (SQL ).
• They are used for defining and accessing
databases .
DATA DEFINITION LANGUAGE (DDL

• Acts as the formal language.


• Generally used by the various computer
professionals.
• Helps in the specification of the database schema.
• The result of the compilation of the Data Definition
Language statements is a set of the tables.
• Defines each of the data element at it appears in the
database.
DATA MANIPULATION LANGUAGE (DML)

• Acts as a very specialized language.


• Mainly used by the end users and the
programmers.
• Helps in manipulating the data in the
database.
• Provides the facility for the retrieval of the
information that has been stored.
• Helps in the insertion of the new information
DATA MANIPULATION LANGUAGE (DML)

• Also helps in deleting some particular information.


• Modifies the stored information.
• Consists of some commands.
• These commands help in the extraction of the
data from the database.
• Satisfies the information requests.
• Helps in the development of the applications.
RELATIONAL ALGEBRA FROM SET THEORY

• The relational algebra is a relation-at-a-time (or set)


language in which all tuples,possibly from several
relations, are manipulated in one statement without
looping.
• The relational algebra uses set union, set difference,
and Cartesian product from set theory, but adds
additional constraints to these operators.
• The fundamental operations of relational algebra
are as follows −
• i. Select ii. Project iii. Union
• iv. Set different v. Cartesian product vi. Rename .
RELATIONAL ALGEBRA FROM SET THEORY
The operations have their own symbols/ Notation
UNARY OPERATIONS
• The Selection and Projection operations are
unary operations, since they operate on one
relation.
• The other operations work on pairs of
relations and are therefore called binary
operations.
RELATIONAL ALGEBRA OPERATIONS

2/28/2019 120
UNARY RELATIONAL OPERATIONS
1.Select Operation (σ)

• It selects tuples that satisfy the given


predicate from a relation.
• Notation − σp(r)
• Where σ stands for selection predicate and r
stands for relation. p is prepositional logic
formula which may use connectors like and,
or, and not.
UNARY RELATIONAL OPERATIONS - SELECT
UNARY RELATIONAL OPERATIONS - SELECT
SELECTION (OR RESTRICTION)
• predicate (R)
• Works on a single relation R and defines a
relation that contains only those tuples (rows) of
R that satisfy the specified condition (predicate).
• Here, the input relation is Staff and the
predicate is salary > 10000. The Selection
operation defines a relation containing only
those Staff tuples with a salary greater than
£10,000. The result of this operation is shown
below.
2/28/2019 124
EXAMPLE
• Using Selection, list all staff with a salary greater
than $10,000
EXAMPLE - SELECTION (OR RESTRICTION)
• List all staff with a salary greater than $10,000?

2/28/2019 126
EXAMPLE - SELECTION (OR RESTRICTION)
• List all staff with a salary greater than $10,000.
salary > 10000 (Staff)

2/28/2019 127
PROJECT OPERATION (Π)

• It projects column(s) that satisfy a given


predicate.
• Notation − ΠA1, A2, An (r)
• Πa1, . . . , an(R) The Projection operation
works on a single relation R and defines a
relation that contains a vertical subset of
R, extracting the values of specified attributes
and eliminating duplicates.
PROJECT OPERATION (Π)
PROJECT OPERATION (Π)
EXAMPLE - PROJECTION
• Produce a list of salaries for all staff, showing
only staffNo, fName, lName, and salary
details?
EXAMPLE - PROJECTION
• Produce a list of salaries for all staff, showing only
staffNo, fName, lName, and salary details.

2/28/2019 132
ANSWER

• In this example, the Projection operation defines


a relation that contains only the designated Staff
attributes staffNo, fName, lName, and salary, in
the specified order
• staffNo, fName, lName, salary(Staff)
BINARY OPERATIONS
• The Selection and Projection operations extract
information from only one relation.
• Thereare obviously cases where we would like to
combine information from several relations.
• Insuch cases we use the binary operations of the
relational algebra, starting with the set operations
of Union, Set difference, Intersection, and Cartesian
product.
UNION OPERATION (∪)

• It performs binary union between two given relations.


• For a union operation to be valid, the following
conditions must hold r, and s must have the same
number of attributes.
• Attribute domains must be compatible.
• Duplicate tuples are automatically eliminated .
UNION
RS
• Union of two relations R and S defines a relation
that contains all the tuples of R, or S, or both R and
S, duplicate tuples being eliminated.
• R and S must be union-compatible.

If R and S have I and J tuples, respectively, union is


obtained by concatenating them into one relation with
a maximum of (I + J) tuples.

2/28/2019 136
EXAMPLE - UNION
• List all cities where there is either a branch
office or a property for rent.

• city(Branch)  city(PropertyForRent)

2/28/2019 137
UNION
• To produce union-compatible relations, we
first use the Projection operation to project
the Branch and PropertyForRent relations
over the attribute city, eliminating duplicates
where necessary.
• We then use the Union operation to combine
these new relations to produce the result .
SET DIFFERENCE
•R – S
• Defines a relation consisting of the tuples that
are in relation R, but not in S.
• R and S must be union-compatible.

2/28/2019 139
EXAMPLE: SET DIFFERENCE

• List all cities where there is a branch office


but no properties for rent.

city(Branch) – city(PropertyForRent)

2/28/2019 140
SET DIFFERENCE
• As in the previous example, we produce union-
compatible relations by projecting the Branch
and PropertyForRent relations over the
attribute city.
• We then use the Set difference operation to
combine these new relations to produce the
result.
INTERSECTION
•R  S
• Defines a relation consisting of the
set of all tuples that are in both R
and S.
• R and S must be union-compatible.

• Expressed using basic operations:


R  S = R – (R – S) 2/28/2019 142
EXAMPLE - INTERSECTION
• List all cities where there is both a branch office and
at least one property for rent.

city(Branch)  city(PropertyForRent)

2/28/2019 143
INTERSECTION

• As in the previous example, we produce union-


compatible relations by projecting the Branch
and PropertyForRent relations over the attribute
city.
• We then use the Intersection operation to
combine these new relations to produce the result
above.
•RXS CARTESIAN PRODUCT
• Defines a relation that is the concatenation of
every tuple of relation R with every tuple of
relation S.
• The Cartesian product operation multiplies two
relations to define another relation consisting
of all possible pairs of tuples from the two
relations.
• Therefore, if one relation has I tuples and N
attributes and the other has J tuples and M
2/28/2019 145
attributes, the Cartesian product relation will
contain (I * J) tuples with (N + M) attributes.
EXAMPLE
• Listthe names and comments of all clients who
have viewed a property for rent?

• The names of clients are held in the Client relation


and the details of viewings are held in
the Viewing relation.
To obtain the list of clients and the comments on
properties they have viewed, we need to combine
these two relations.
(ΠclientNo, fName, lName(Client)) × (ΠclientNo,
propertyNo, comment(Viewing))
CARTESIAN PRODUCT
CARTESIAN PRODUCT

• In its present form, this relation contains more information


than we require.
• To obtain the required list, we need to carry out a
Selection operation on this relation to extract those tuples
where :
Client.clientNo = Viewing.clientNo.
• The complete operation is thus:
EXAMPLE - CARTESIAN PRODUCT
AND SELECTION
• Use selection operation to extract those tuples
where Client.clientNo = Viewing.clientNo.
Client.clientNo = Viewing.clientNo((clientNo, fName, lName(Client))  (clientNo,
propertyNo, comment(Viewing)))

 Cartesian product and Selection can be reduced to a single


operation called a Join. 2/28/2019 149
JOIN OPERATIONS
• Typically, we want only combinations of the Cartesian product
that satisfy certain conditions
and so we would normally use a Join operation instead of the
Cartesian product operation.
Various forms of Join operation,
• Theta join
• Equijoin (a particular type of Theta join)
• Natural join
• Outer join
• Semijoin.
• Go and Research on these
STRUCTURED QUERY LANGUAGE (SQL)
OBJECTIVES OF SQL
 Ideally, database language should allow user to:
 create the database and relation structures;
 perform insertion, modification, deletion of data from relations;
 perform simple and complex queries.
 Must perform these tasks with minimal user effort
and command structure/syntax must be easy to
learn.
 It must be portable.
HCT303 Application of Database systems 2/28/2019 152
OBJECTIVES OF SQL

• SQLis a transform-oriented language with 2


major components:
• A DDL for defining database structure.
• A DML for retrieving and updating data.
• SQL is relatively easy to learn:
• it is non-procedural - you specify what information you
require, rather than how to get it;
• it is essentially free-format.
2/28/2019 153
WRITING SQL COMMANDS
• SQL statement consists of reserved words and
user-defined words.
–Reserved words are a fixed part of SQL and
must be spelt exactly as required and cannot
be split across lines.
–User-defined words are made up by user
and represent names of various database
objects such as relations, columns, views.

HCT303 Application of Database systems 2/28/2019 154


WRITING SQL COMMANDS
• Most components of an SQL statement are case
insensitive, except for literal character data.
• More readable with indentation and lineation:
• Each clause should begin on a new line.
• Start of a clause should line up with start of
other clauses.
• If clause has several parts, should each
appear on a separate line and be indented
under start of clause.
HCT303 Application of Database systems 2/28/2019 155
LITERALS
• Literals are constants used in SQL
statements.

• All non-numeric literals must be enclosed in


single quotes (e.g. ‘London’).

• All numeric literals must not be enclosed in


quotes (e.g. 650.00).

HCT303 Application of Database systems 2/28/2019 156


SELECT STATEMENT
SELECT
FROM Specifies table(s) to be used.
WHERE Filters rows.

HCT303 Application of Database systems 2/28/2019 157


SELECT STATEMENT

• Order of the clauses cannot be changed.

• Only SELECT and FROM are mandatory.

HCT303 Application of Database systems 2/28/2019 158


ALL COLUMNS, ALL ROWS
List full details of all staff.

SELECT staffNo, fName, lName, position, sex,


DOB, salary, branchNo
FROM Staff;

• Can use * as an abbreviation for ‘all


columns’:

SELECT *
FROM Staff;
EXAMPLE; ALL COLUMNS, ALL ROWS

HCT303 Application of Database systems 2/28/2019 160


EXAMPLE; SPECIFIC COLUMNS,
ALL ROWS

Produce a list of salaries for all staff, showing only


staff number, first and last names, and salary.

SELECT staffNo, fName, lName, salary


FROM Staff;

HCT303 Application of Database systems 2/28/2019 161


EXAMPLE; SPECIFIC COLUMNS,
ALL ROWS

HCT303 Application of Database systems 2/28/2019 162


EXAMPLE; USE OF DISTINCT
List the property numbers of all properties that have
been viewed.

SELECT propertyNo
FROM Viewing;

2/28/2019 163
USE OF DISTINCT: EXAMPLE

• Use DISTINCT to eliminate duplicates:

SELECT DISTINCT propertyNo


FROM Viewing;

HCT303 Application of Database systems 2/28/2019 164


EXAMPLE; CALCULATED FIELDS
Produce a list of monthly salaries for all
staff, showing staff number, first and last
names, and salary details.
SELECT staffNo, fName, lName, salary
FROM Staff;

HCT303 Application of Database systems 2/28/2019 165


EXAMPLE; COMPARISON SEARCH
CONDITION
List all staff with a salary greater than 10,000.

SELECT staffNo, fName, lName, position, salary


FROM Staff
WHERE salary > 10000;

HCT303 Application of Database systems 2/28/2019 166


EXAMPLE; COMPOUND COMPARISON SEARCH
CONDITION

List addresses of all branch offices in London or


Glasgow.

SELECT *
FROM Branch
WHERE city = ‘London’ OR city = ‘Glasgow’;

HCT303 Application of Database systems 2/28/2019 167


EXAMPLE; RANGE SEARCH
CONDITION
List all staff with a salary between 20,000 and
30,000.

SELECT staffNo, fName, lName, position, salary


FROM Staff
WHERE salary BETWEEN 20000 AND 30000;

• BETWEEN test includes the endpoints of range.


HCT303 Application of Database systems 2/28/2019 168
EXAMPLE; RANGE SEARCH
CONDITION

HCT303 Application of Database systems 2/28/2019 169


EXAMPLE; RANGE SEARCH
CONDITION
• Also a negated version NOT BETWEEN.
• BETWEEN does not add much to SQL’s expressive
power. Could also write:

SELECT staffNo, fName, lName, position, salary


FROM Staff
WHERE salary>=20000 AND salary <= 30000;

• Useful, though, for a range of values.


HCT303 Application of Database systems 2/28/2019 170
INSERT

INSERT INTO TableName [ (columnList) ]


VALUES (dataValueList)

• columnList is optional; if omitted, SQL assumes a


list of all columns in their original CREATE TABLE
order.
• Any columns omitted must have been declared as
NULL when table was created, unless DEFAULT
was specified when creating column.

HCT303 Application of Database systems 2/28/2019 171


INSERT
• dataValueList must match columnList as follows:
• number of items in each list must be same;
• must be direct correspondence in position of items in
two lists;
• data type of each item in dataValueList must be
compatible with data type of corresponding column.

HCT303 Application of Database systems 2/28/2019 172


EXAMPLE; INSERT … VALUES
Insert a new row into Staff table supplying
data for all columns.

INSERT INTO Staff


VALUES (‘SG16’, ‘Alan’, ‘Brown’, ‘Assistant’, ‘M’, Date‘1957-05-
25’, 8300, ‘B003’);

HCT303 Application of Database systems 2/28/2019 173


EXAMPLE; INSERT USING DEFAULTS
Insert a new row into Staff table supplying data
for all mandatory columns.

INSERT INTO Staff (staffNo, fName, lName,


position, salary,
branchNo)
VALUES (‘SG44’, ‘Anne’, ‘Jones’,
‘Assistant’, 8100, ‘B003’);
• Or
INSERT INTO Staff
VALUES (‘SG44’, ‘Anne’, ‘Jones’, ‘Assistant’, NULL,
NULL,
HCT303 Application of 8100, ‘B003’);
Database systems 2/28/2019 174
INSERT … SELECT
• Second form of INSERT allows multiple rows
to be copied from one or more tables to
another:

INSERT INTO TableName [ (columnList) ]


SELECT ...

HCT303 Application of Database systems 2/28/2019 175


EXAMPLE; INSERT … SELECT
Assume there is a table StaffPropCount that contains
names of staff and number of properties they
manage:

StaffPropCount(staffNo, fName, lName, propCnt)

Populate StaffPropCount using Staff and


PropertyForRent tables.

HCT303 Application of Database systems 2/28/2019 176


EXAMPLE; INSERT … SELECT

INSERT INTO StaffPropCount


SELECT s.staffNo, fName, lName,
FROM Staff s, PropertyForRent p
WHERE s.staffNo = p.staffNo

HCT303 Application of Database systems 2/28/2019 177


EXAMPLE INSERT … SELECT

• If second part of UNION is omitted, excludes those staff who


currently do not manage any properties.

HCT303 Application of Database systems 2/28/2019 178


UPDATE

UPDATE TableName
SET columnName1 = dataValue1
[, columnName2 = dataValue2...]
[WHERE searchCondition]

• TableName can be name of a base table or an


updatable view.
• SET clause specifies names of one or more
columns that are to be updated.

HCT303 Application of Database systems 2/28/2019 179


UPDATE
• WHERE clause is optional:
• if omitted, named columns are updated
for all rows in table;
• if specified, only those rows that satisfy
searchCondition are updated.

• New dataValue(s) must be compatible with


data type for corresponding column.
HCT303 Application of Database systems 2/28/2019 180
EXAMPLE; UPDATE ALL ROWS
Give all staff a 3% pay increase.

UPDATE Staff
SET salary = salary*1.03;

Give all Managers a 5% pay increase.

UPDATE Staff
SET salary = salary*1.05
WHERE position = ‘Manager’;
HCT303 Application of Database systems 2/28/2019 181
EXAMPLE; UPDATE MULTIPLE
COLUMNS
Promote David Ford (staffNo=‘SG14’) to
Manager and change his salary to £18,000.

UPDATE Staff
SET position = ‘Manager’, salary = 18000
WHERE staffNo = ‘SG14’;

HCT303 Application of Database systems 2/28/2019 182


DELETE
DELETE FROM TableName
[WHERE searchCondition]

• TableNamecan be name of a base table or


an updatable view.
• searchCondition is optional; if omitted, all rows
are deleted from table. This does not delete
table. If search_condition is specified, only
2/28/2019 183
those rows that satisfy condition are deleted.
EXAMPLE; DELETE SPECIFIC
ROWS
Delete all viewings that relate to property
PG4.

DELETE FROM Viewing


WHERE propertyNo = ‘PG4’;

Delete all records from the Viewing table.


DELETE FROM Viewing;
HCT303 Application of Database systems 2/28/2019 184
CLASS EXAMPLE

Lecturer (staffno: integer, name: string, address: string)


Course (courseid: integer, name: string, description: string)

Department (dptmtid: integer, name: string)

• Give an expression in SQL for each of the following queries


1.Find the names of lecturers who stay at number 9 nande villas Bindura.
[3]
2.Find the name of a lecturer whose staff number is 693 [3]

3. Find the name of the department whose department id is IT207.


[3]
TRANSACTION MANAGEMENT
TRANSACTION

• A transaction is defined as follows:


i)A logical unit of database operations which are
executed as a whole to process user requests for
retrieving data or updating the database
ii)According to Ramakrishnan and Gehrke, a
transaction is seen by the DBMS as a series or list
of actions
TRANSACTION

• The actions that can be executed by a transaction


include the read(retrieval) and write (insertion,
updating and deletion) operations
PROPERTIES OF A TRANSACTION

A DBMS must ensure four important properties of


transactions to maintain data in the face of concurrent
access and system failures
The acronym ACID is sometimes used to refer to these four
properties
ATOMICITY

• It is aka the “all or nothing property”


• It states that ‘ users should be able to regard the
execution of each transaction as atomic i.e. either all
actions are carried out or none are
• Users should not have to worry about the effect of
incomplete transactions say for example when a
system crash occurs
CONSISTENCY
•A transaction must transform the database from
one consistent state to another
• The DBMS assumes that consistency holds for
each transaction whilst the user ensures that a
transaction holds this property
• The DBMS can ensure consistency by enforcing all
the constraints that have been specified on the
database schema such as integrity and
enterprise constraints
CONSISTENCY…..

• It is the responsibility of the application programmers


who code the transactions to ensure consistency of the
database. Note that during the execution of the
transaction the state of the database becomes
inconsistent. Such an inconsistent state of the
database should not be visible to the users or other
concurrently running transactions.
ISOLATION

• Transactions execute independently of one another


• This means that users should be able to understand a
transaction without considering the effect of other
concurrently executing transactions
• It is the responsibility of the concurrency control
subsystem to ensure isolation
DURABILITY

• Once the DBMS informs the users that a


transaction has been successfully completed, its
effects should persist even if the system crashes
before all its changes are reflected on disk
• Is ensured by the recovery manager.
STATES OF A TRANSACTION

Whenever a transaction is submitted to a DBMS


for execution, either it executes successfully or
fails due to some reasons. During its execution, a
transaction passes through various states that are
active, partially committed, committed, failed,
and aborted.
The Fig below shows the state transition diagram
that describes how a transaction passes through
various states during its execution.
STATE TRANSITION DIAGRAM FOR
TRANSACTION
TRANSACTION STATES

• ACTIVE STATE- this is the initial state of a transaction;


transaction stays in this state while it is executing
• A transaction can have one of two outcomes; if it completes
successfully the transaction is said to have COMMITTED and
the database reaches a new state; on the other hand if the
transaction does not execute successfully the transaction is
ABORTED or TERMINATED; if it is aborted, it must be
restored to the consistent state it was in before the transaction
started; Such a transaction is rolled back or undone
TRANSACTION STATES
CONTINUED………
• The keywords BEGIN TRANSACTION, COMMIT TRANSACTION and
ABORT (rollback) are available in many data manipulation
languages to delimit transactions
• PARTIALLY COMMITTED- it occurs after the final statement has been
executed; the system may fail and any data updated by the
transaction may not have been safely recorded on secondary
storage; in such cases the transaction would go into the FAILED state
and would have to be aborted; if it is successful, any updates can be
safely recorded and the transaction can go to the COMMITTED state
• FAILED state occurs if the transaction can not be committed or the
transaction is aborted while in the ACTIVE state.
DATABASE MANAGEMENT SYSTEM
ARCHITECTURE
DBMS TRANSACTION SUBSYSTEM
DBMS TRANSACTION SYSYEM…
• It identifies four high level database modules that handle
transactions, concurrency control and recovery

• The TRANSACTION MANAGER coordinates transactions


on behalf of application programs; it communicates with
the SCHEDULER which is the module that is responsible
for implementing a particular strategy for concurrency
control
DBMS TRANSACTION SYSYEM…

• Scheduler is sometimes referred to as the LOCK


MANAGER if the concurrency control protocol is
locking- based; the objective of the scheduler is
to maximize concurrency without allowing
concurrently executing transactions to interfere
with one another and so compromise the integrity
or consistency of the database
DBMS TRANSACTION SYSYEM…

• If a failure occurs during the transaction, it is the task


of the RECOVERY MANAGER to ensure that the
database is restored to the state it was in before the
start of the transaction (a consistent state)
• BUFFER MANAGER is responsible for the transfer of
data between disk storage and main memory
DATABASE SECURITY
• A database is a very important part of any organisation
that you may think of. It holds different items which make
an organisation run ranging from equipment to payrolls.
• Because of the importance of these records to an
organisation, there is need to protect them from whatever
threats, known or unknown that may affect the integrity of
the data.
• Asa result, it is important to think of security whenever
we think of designing and implementing a database.
DATABASE SECURITY…
• Database security refers to the protection of the
database against intentional or unintentional threats
using computer based or non computer based control.
• Database security encompasses hardware, software,
people and data.
• To effectively implement security it requires appropriate
controls which are defined in specific policy statements
that meet the requirements of the system.
•A database represents an essential corporate resource
that should be properly secured using appropriate
control measures.
• Database security is considered in relation to the
following situations.
DATABASE SECURITY
Theft and fraud
• Activities resulting in theft and fraud are perpetrated by
people and therefore attention should focus on
reducing the opportunities for this occurring, for example
keeping salary payments stationary secured.
Loss of confidentiality / loss of privacy
• Confidentiality – Refers to the need to maintain secrecy
over data usually only that which is critical to the
organisation whereas privacy refers to the need to
protect data about individuals.
DATABASE SECURITY
• Loss of integrity / Loss of availability
Loss of data integrity results in invalid or corrupt
data which may seriously affect the operation of
an organisation. Loss of availability means that the
data or the system or both cannot be accessed
which can jeopardise an organisation’s existence.
THREATS TO DATABASE SECURITY
• A threat is any situation or event whether intentional
or unintentional that will adversely affect a system
and consequently an organisation.
• The harm may be tangible such as loss of hardware,
software or data or intangible such as loss of
credibility or client confidence.
• The problem facing any organisation is to identify
all possible threats some of which will be difficult to
detect.
• The following are some examples of threats.
THREATS TO DATABASE SECURITY
• Using another person’s means of access may result in
theft or fraud, loss of confidentiality and loss of
privacy.
• Unauthorised amendment or copying of data may
result in theft and fraud and loss of integrity.
• Program alterations; May result in loss of availability,
loss of integrity, loss of privacy and theft and fraud.
• Introduction of viruses.
• Physical damage to equipment
• Inadequate staff training
COUNTER MEASURES:
COMPUTER BASED CONTROL

• The type of counter measures to threats on computer


systems range from physical controls to administrative
procedures.
• Computer based security controls for the multi-user
environment include the following:
COUNTER MEASURES:
COMPUTER BASED CONTROL
Authorisation
• Granting of the right or privilege which enables a subject to have
legitimate access to a systems object.
Authentication
• Is a mechanism that determines whether a user is who he/she claims to
be.
Backup and Recovery
• The process of periodically taking a copy of the database and log
files and possible programs on to offline storage media.
Encryption
• The encoding of the data by special algorithm that renders the data
unreadable by any program without the decryption key.
COUNTER MEASURES:
COMPUTER BASED CONTROL
Audit Trail
• Used to record every operation on the database. For each
operation the journal will typically include the following
information:
• An identification of the transaction concerned
• A time stamp
• An identification of the terminal and user concerned
• The full text of the input change
• And in the case of an operation involving change to the
database, the type of change and address of the data
changed, together with its before and after values
NON-COMPUTER BASED CONTROLS

• Security policy and contingency plan


• Personnel control
• Physical access controls
PRESENTATION AREAS

• Types of normal forms 1NF, 2NF, 3NF, BCNF, and


4NF
• Unary relational operations
• Relational algebra from set theory
• Binary relational operations
• Insert, Delete and Update statements in SQL

You might also like