DBMS Merged
DBMS Merged
File-based Approach
A collection of application programs that perform services for the end-users such as the
production of reports. Each program defines and manages its own data.
File
A file is simply a collection of records, which contains logically related data.
EXAMPLE OF FILE BASED APPROACH
LIMITATIONS OF THE FILE-BASED APPROACH
Arose because:
Definition of data was embedded in application programs, rather than being stored
separately and independently.
No control over access and manipulation of data beyond that imposed by
application programs.
Result:
the database and Database Management System (DBMS).
Database
A shared collection of logically related data (and a
description of this data), designed to meet the information
needs of an organization.
Benefits of Views:
Reduce complexity
Provide a level of security
Provide a mechanism to customize the appearance of the database
Present a consistent, unchanging picture of the structure of the database, even if the underlying
database is changed
Components of DBMS Environment
Hardware
It can range from a PC to a network of computers.
Software
DBMS, operating system, network software (if necessary) and also the application programs.
Data
Used by the organization and a description of this data called the schema.
Procedures
Instructions and rules that should be applied to the design and use of the database and DBMS.
People
Includes database designers, DBAs, application programmers, and end-users.
Roles in the Database Environment
Data Administrator (DA)
Database Administrator (DBA)
Database Designers (Logical and Physical)
Application Programmers
End Users (naive and sophisticated)
ADVANTAGES OF DBMS
Control of data redundancy
Data consistency
More information from the same amount of data
Sharing of data
Improved data integrity
Improved security
Enforcement of standards
Economy of scale
Balance conflicting requirements
Improved data accessibility and responsiveness
Increased productivity
Improved maintenance through data independence
Increased concurrency
Improved backup and recovery services
THE THREE-LEVEL ANSI-SPARC ARCHITECTURE
The levels form a three-level architecture comprising an external, a
conceptual, and an internal level, as depicted in Figure
OBJECTIVES OF THREE LEVEL ARCHITECTURE
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.
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.
The Database Administrator (DBA) should be able to change the database storage structures
without affecting the users’ views.
The internal structure of the database should be unaffected by changes to the physical aspects
of storage, such as the changeover to a new storage device.
The DBA should be able to change the conceptual structure of the database without affecting all
users.
EXTERNAL LEVEL
The users’ view of the database. This level describes that part of the level database that is relevant
to each user.
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.
The conceptual level represents:
all entities, their attributes, and their relationships
the constraints on the data
semantic information about the data
security and integrity information.
INTERNAL LEVEL
The physical representation of the database on the computer. This level describes how the data is
stored in the database. The internal level is concerned with such things as:
storage space allocation for data and indexes
record descriptions for storage (with stored sizes for data items)
record placement
data compression and data encryption techniques
Difference between Three Levels of ANSI
APARC Architecture
DATA INDEPENDENCE
LOGICAL DATA INDEPENDENCE
Logical data independence refers to the immunity of the external independence
schemas to changes in the conceptual schema.
PROCEDURAL DMLS
A language that allows the user to tell the system what data is needed and
exactly how to retrieve the data.
NON-PROCEDURAL DMLS
A language that allows the user to state what data is needed rather than how it is
to be retrieved.
Fourth-Generation Languages (4GLs)
Fourth generation languages encompass:
presentation languages, such as query languages and report generators;
speciality languages, such as spreadsheets and database languages;
application generators that define, insert, update, and retrieve data from the
database to build applications;
very high-level languages that are used to generate application code.
SQL and QBE, mentioned above, are examples of 4GLs.
We now briefly discuss some of the other types of 4GL.
▪ Forms generators
▪ Report generators
▪ Graphics generators
▪ Application generators
Data Models and Conceptual Modeling
DATA MODEL:
An integrated collection of concepts for describing and manipulating data,
relationships between data, and constraints on the data in an organization.
Data model comprises:
(1) a structural part, consisting of a set of rules according to which
databases can be constructed
(2) a manipulative part, defining the types of operation that are allowed on
the data (this includes the operations that are used for updating or
retrieving data from the database and for changing the structure of the
database)
(3) possibly a set of integrity constraints, which ensures that the data is
accurate.
DATA MODEL
Purpose
To represent data in an understandable way.
To reflect the ANSI-SPARC architecture discussed in lecture 3, we can identify
three related data models:
an external data model, to represent each user’s view of the organization,
sometimes called the Universe of Discourse (UoD);
a conceptual data model, to represent the logical (or community) view that is
DBMS independent;
an internal data model, to represent the conceptual schema in such a way that it
can be understood by the DBMS.
Categories of data model includes:
object-based
record-based
physical
Object-Based Data Models
Object-based data models use concepts such as entities, attributes, and
relationships.
An entity is a distinct object (a person, place, thing, concept, event) in the
organization that is to be represented in the database.
An attribute is a property that describes some aspect of the object that we wish to
record.
a relationship is an association between entities.
Some of the more common types of object-based data model are:
Entity–Relationship(ER)
Semantic
Functional
Object-Oriented
Record-Based Data Models
In a record-based model, the database consists of a
number of fixed-format records possibly of differing
types. Each record type defines a fixed number of fields,
each typically of a fixed length.
There are three principal types of record-based logical
data model:
the relational data model,
the network data model, and
the hierarchical data model.
Relational data model
The relational data model is based on the concept of mathematical relations.
In the relational model, data and relationships are represented as tables,
each of which has a number of columns with a unique name. Figure 4.1 is a
sample instance of a relational schema for part of the DreamHome case study,
showing branch and staff details.
As the file-server has no knowledge of SQL, the DBMS has to request the files
corresponding to the Branch and Staff relations from the file-server, rather
than just the staff names that satisfy the query.
The file-server architecture, therefore, has three main disadvantages:
There is a large amount of network traffic.
A full copy of the DBMS is required on each workstation.
Concurrency, recovery, and integrity control are more complex because there can
be multiple DBMSs accessing the same files.
Traditional Two-Tier Client–Server Architecture
Client (tier 1) manages user interface and runs applications.
Server (tier 2) holds database and DBMS.
Figure 5.7:
Four-tier
architecture
with the middle
tier split into a
Web server and
application
server
Middleware
Middleware is a generic term used to describe software that
mediates with other software and allows for communication
between disparate applications in a heterogeneous system.
The need for middleware arises when distributed systems become
too complex to manage efficiently without a common interface.
Six main types of middleware are as follows:
Asynchronous Remote Procedure Call (RPC)
Synchronous RPC
Publish/subscribe
Message-oriented middleware (MOM)
Object-request broker (ORB)
SQL-oriented data access
Transaction Processing Monitors
TP monitor is a program that controls data transfer between
clients and servers in order to provide a consistent
environment, particularly for online transaction processing
(OLTP).
Figure 5.8:
Transaction
Processing Monitor
as middletierof
3-tierclient-server
TP Monitors provide significant advantages, including:
Transaction routing
Managing distributed transactions
Load balancing
Funneling
Increased reliability
Web Services andService-Oriented Architectures
Distributed DBMSs
➢ A distributed database is a logically interrelated collection of
shared data (and a description of this data), physically
distributed over a computer network.
➢ A distributed DBMS is the software system that permits the
management of the distributed database and makes the
distribution transparent to users.
➢ A DDBMS consists of a single logical database split into a number of
fragments.
➢ Each fragment is stored on one or more computers (replicas) under
the control of a separate DBMS, with the computers connected by a
network.
➢ Each site is capable of independently processing user requests that
require access to local data (that is, each site has some degree of local
autonomy) and is also capable of processing data stored on other
computers in the network.
Figure 6.2:
Distributed database
management system
Distributed Processing
A centralized database that can be accessed over a computer network.
3
Cloud Computing – Service Models
Software as a Service (SaaS):
Software and data hosted on cloud. Accessed
through using thin client interface (e.g. web
browser). Consumer may be offered limited user
specific application configuration settings.
Examples include Salesforce.com sales management
applications, NetSuite’s integrated business
management software, Google’s Gmail and
Cornerstone OnDemand.
4
Cloud Computing – Service Models
Platform as a Service (PaaS)
Allows creation of web applications without
buying/maintaining the software and underlying
infrastructure. Provider manages the infrastructure
including network, servers, OS and storage, while
customer controls deployment of applications and
possibly configuration.
Examples include Salesforce.com’s Force.com,
Google’s App Engine, and Microsoft’s Azure.
5
Cloud Computing – Service Models
Infrastructure as a Service (IaaS)
Provider’s offer servers, storage, network and
operating systems – typically a platform
virtualization environment – to consumers as an
on-demand service, in a single bundle and billed
according to usage.
A popular use of IaaS is in hosting websites.
Examples Amazon’s Elastic Compute Cloud (EC2),
Rackspace and GoGrid.
Cloud Computing – Comparison of
Services Models
Four main deployment models
for the cloud
Public cloud
Private cloud
Community cloud
Hybrid cloud
Benefits of Cloud Computing
Cost-Reduction: Avoid up-front capital expenditure.
Scalability/Agility: Organisations set up resources on an
as-needs basis.
Improved Security: Providers can devote expertise &
resources to security; not affordable by customer.
Improved Reliability: Providers can devote expertise &
resources on reliability of systems; not affordable by
customer.
Access to new technologies: Through use of provider’s
systems, customers may access latest technology.
Faster development: Provider’s platforms can provide
many of the core services to accelerate development
cycle.
9
Benefits of CloudComputing
Large scale prototyping/load testing: Providers
have the resources to enable this.
More flexible working practices: Staff can access
files using mobile devices.
Increased competitiveness: Allows organizations to
focus on their core competencies rather than their IT
infrastructures.
10
Risks of Cloud Computing
Network Dependency: Power outages, bandwidth
issues and service interruptions.
System Dependency: Customer’s dependency on
availability and reliability of provider’s systems.
Cloud Provider Dependency: Provider could became
insolvent or acquired by competitor, resulting in
the service suddenly terminating.
Lack of control: Customers unable to deploy
technical or organisational measures to safeguard
the data. May result in reduced availability,
integrity, confidentiality, intervenability and
isolation.
Lack of information on processing transparency:
Insufficient information about a cloud service’s
processing operations poses a risk to data controllers
as well as to data subjects because they might not be
aware of potential threats and risks and thus cannot
take measures they deem appropriate
Cloud-based database solutions
➢ DBaaS
Offers full database functionality to
application developers.
Provides a management layer that provides
continuous monitoring and configuring of the
database to optimized scaling, high
availability, multi-tenancy (that is, serving
multiple client organizations), and effective
resource allocation in the cloud, thereby
sparing the developer from ongoing database
administration tasks.
Cloud-based database solutions
DaaS:
Services enables data definition in the
cloud and subsequently querying.
Does not implement typical DBMS
interfaces (e.g. SQL) but instead data is
accessed via common APIs.
Enables organization with valuable data to
offer access to others. Examples Urban
Mapping (geography data service), Xignite
(financial data service) and Hoovers
(business data service.)
Components of aDBMS
A DBMS is partitioned into several software
components (or modules), each of which is
assigned a specific operation. As stated
previously, some of the functions of the DBMS
are supported by the underlying operating
system.
The DBMS interfaces with other software
components, such as user queries and access
methods (file management techniques for
storing and retrieving data records).
Components of a DBMS
Components of aDBMS (Contd..)
Query processor is a major DBMS component
that transforms queries into a series of low-
level instructions directed to the database
manager.
Database manager (DM) interfaces with
user-submitted application programs and
queries. The DM examines the external and
conceptual schemas to determine what
conceptual records are required to satisfy
the request. The DM then places a call to the
file manager to perform the request.
Components of aDBMS (Contd..)
File manager manipulates the underlying
storage files and manages the allocation of
storage space on disk. It establishes and
maintains the list of structures and indexes
defined in the internal schema.
DML preprocessor converts DML statements
embedded in an application program into
standard function calls in the host language.
The DML preprocessor must interact with the
query processor to generate the appropriate
code.
Components of aDBMS (Contd..)
DDL compiler converts DDL statements into
a set of tables containing metadata. These
tables are then stored in the system
catalog while control information is stored
in data file headers.
Catalog manager manages access to and
maintains the system catalog. The system
catalog is accessed by most DBMS
components.
Components of Database Manager (DM)
Components of theDatabase Manager
Authorization control to confirm whether the
user has the necessary permission to carry out
the required operation.
Command processor on confirmation of user
authority, control is passed to the command
processor.
Integrity checker ensures that requested
operation satisfies all necessary integrity
constraints (e.g. key constraints) for an
operation that changes the database.
Components of theDatabase Manager (Contd..)
◆ Candidate Key
– Superkey (K) such that no proper subset is a
superkey within the relation.
– In each tuple of R, values of K uniquely identify
that tuple (uniqueness).
– No proper subset of K has the uniqueness
property (irreducibility).
Relational Keys
◆ Primary Key
– Candidate key selected to identify tuples uniquely
within relation.
◆ Alternate Keys
– Candidate keys that are not selected to be primary
key.
◆ Foreign Key
– Attribute, or set of attributes, within one relation
that matches candidate key of some (possibly same)
relation.
Integrity Constraints
◆ Null
– Represents value for an attribute that is
currently unknown or not applicable for
tuple.
– Deals with incomplete or exceptional data.
– Represents the absence of a value and is
not the same as zero or spaces, which are
values.
Integrity Constraints
◆ Entity Integrity
– In a base relation, no attribute of a
primary key can be null.
◆ Referential Integrity
– If foreign key exists in a relation, either
foreign key value must match a
candidate key value of some tuple in its
home relation or foreign key value must
be wholly null.
Integrity Constraints
◆ General Constraints
– Additional rules specified by users or
database administrators that define or
constrain some aspect of the enterprise.
Views
◆ Base Relation
– Named relation corresponding to an entity
in conceptual schema, whose tuples are
physically stored in database.
◆ View
– Dynamic result of one or more relational
operations operating on base relations to
produce another relation.
Views
◆A virtual relation that does not necessarily
actually exist in the database but is
produced upon request, at time of request.
www.bzupages.com
Relational Algebra
3
www.bzupages.com
Relational Algebra
Five basic operations in relational algebra:
Selection, Projection, Cartesian product, Union,
and Set Difference.
4
www.bzupages.com
Relational Algebra Operations
5
www.bzupages.com
Relational Algebra Operations
6
www.bzupages.com
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).
7
www.bzupages.com
Example - Selection (or Restriction)
8
www.bzupages.com
Projection
col1, . . . , coln(R)
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.
9
www.bzupages.com
Example - Projection
10
www.bzupages.com
Union
RS
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.
11
www.bzupages.com
Example - Union
List all cities where there is either a branch office or a property for
rent.
city(Branch) city(PropertyForRent)
12
www.bzupages.com
Set Difference
R–S
Definesa relation consisting of the
tuples that are in relation R, but not in
S.
R and S must be union-compatible.
13
www.bzupages.com
Example - Set Difference
List all cities where there is a branch office but no properties
for rent.
city(Branch) – city(PropertyForRent)
14
www.bzupages.com
Intersection
RS
Defines a relation consisting of the set of all tuples
that are in both R and S.
R and S must be union-compatible.
15
www.bzupages.com
Example - Intersection
List all cities where there is both a branch office and at least one
property for rent.
city(Branch) city(PropertyForRent)
www.bzupages.com
Cartesian product
RXS
Defines a relation that is the concatenation of every tuple of relation R
with every tuple of relation S.
17
www.bzupages.com
Example - Cartesian product
List the names and comments of all clients who have viewed a property
for rent.
18
www.bzupages.com
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)))
20
www.bzupages.com
Join Operations
Various forms of join operation
Theta join
Equijoin (a particular type of Theta join)
Natural join
Outer join
Semijoin
www.bzupages.com
Theta join (-join)
R FS
22
www.bzupages.com
Theta join (-join)
R FS = F(R S)
23
www.bzupages.com
Example - Equijoin
List the names and comments of all clients who have viewed a property
for rent.
(clientNo, fName, lName(Client)) Client.clientNo = Viewing.clientNo (clientNo, propertyNo,
comment(Viewing))
24
www.bzupages.com
Natural join
R S
An Equijoin of the two relations R and S over all
common attributes x. One occurrence of each
common attribute is eliminated from the result.
25
www.bzupages.com
Example - Natural join
List the names and comments of all clients who have viewed a property
for rent.
(clientNo, fName, lName(Client))
(clientNo, propertyNo, comment(Viewing))
26
www.bzupages.com
Outer join
R S
(Left) outer join is join in which tuples from
R that do not have matching values in
common columns of S are also included in
result relation.
27
www.bzupages.com
Example - Left Outer join
28
www.bzupages.com
Semijoin
R FS
Defines a relation that contains the tuples
of R that participate in the join of R with
S.
R FS = A(R F S)
29
www.bzupages.com
Example - Semijoin
List complete details of all staff who work at the branch in Glasgow.
Staff Staff.branchNo=Branch.branchNo(city=‘Glasgow’(Branch))
30
www.bzupages.com
Lecture #11
Relational algebra and Relational Calculus
(contd…)
Division
R S
Defines a relation over the attributes C that
consists of set of tuples from R that match
combination of every tuple in S.
2
Example - Division
Identify all clients who have viewed all properties with three rooms.
(clientNo, propertyNo(Viewing))
(propertyNo(rooms = 3 (PropertyForRent)))
3
Aggregate Operations
AL(R)
Applies aggregate function list, AL, to R to define a relation over the
aggregate list.
AL contains one or more (<aggregate_function>, <attribute>) pairs .
Main aggregate functions are: COUNT, SUM, AVG, MIN, and MAX.
4
Example – Aggregate Operations
How many properties cost more than £350 per month to rent?
GAAL(R)
Groups tuples of R by grouping attributes, GA, and then applies aggregate
function list, AL, to define a new relation.
AL contains one or more (<aggregate_function>, <attribute>) pairs.
Resulting relation contains the grouping attributes, GA, along with results
of each of the aggregate functions.
Example – Grouping Operation
Find the number of staff working in each branch and the sum of
their salaries.
8
Relational Calculus
9
Tuple Relational Calculus
Tuple variable is a variable that ‘ranges over’ a named relation: i.e., variable
whose only permitted values are tuples of the relation.
10
Tuple Relational Calculus - Example
11
Tuple Relational Calculus
Can use two quantifiers to tell how many instances the predicate applies to:
Existential quantifier $ (‘there exists’)
Universal quantifier " (‘for all’)
12
Tuple Relational Calculus
Existential quantifier used in formulae that must be true for at least one
instance, such as:
Staff(S) ($B)(Branch(B)
(B.branchNo = S.branchNo) B.city = ‘London’)
13
Tuple Relational Calculus
Can also use ~($B) (B.city = ‘Paris’) which means ‘There are no branches with
an address in Paris’.
14
Domain Relational Calculus
Uses variables that take values from domains instead of tuples of
relations.
If F(d1, d2, . . . , dn) stands for a formula composed of atoms and d1, d2, . .
. , dn represent domain variables, then:
{d1, d2, . . . , dn | F(d1, d2, . . . , dn)}
is a general domain relational calculus expression.
15
Example - Domain Relational Calculus
Find the names of all managers who earn more than £25,000.
16
Example - Domain Relational Calculus
17
Example - Domain Relational Calculus
List the names of staff who currently do not manage any properties for rent.
{fN, lN | ($sN)
(Staff(sN,fN,lN,posn,sex,DOB,sal,bN)
(~($sN1) (PropertyForRent(pN, st, cty, pc, typ,
rms, rnt, oN, sN1, bN1) (sN=sN1))))}
18
Example - Domain Relational Calculus
List the names of clients who have viewed a property for rent in Glasgow.
20
Other Languages
21
Other Languages
22
Lecture#12
SQL: Data Manipulation
www.bzupages.com
OBJECTIVES
Purpose and importance of SQL.
How to retrieve data from database using SELECT and:
www.bzupages.com
Objectives of SQL
www.bzupages.com
Objectives of SQL
SQL is a transform-oriented language with 2 major
components:
www.bzupages.com
Objectives of SQL
SQL is relatively easy to learn:
www.bzupages.com
Objectives of SQL
An ISO standard now exists for SQL, making it both the formal
and de facto standard language for relational databases.
www.bzupages.com
Importance of SQL
SQL has become part of application architectures such as
IBM’s Systems Application Architecture.
SQL is Federal Information Processing Standard (FIPS) to
which conformance is required for all sales of databases to
American Government.
SQL is used in other standards and even influences
development of other standards as a definitional tool.
Examples include:
www.bzupages.com
Writing SQL Commands
www.bzupages.com
Writing SQL Commands
www.bzupages.com
Writing SQL Commands
10
www.bzupages.com
Literals
11
www.bzupages.com
SELECT Statement
SELECT [DISTINCT | ALL]
{* | [columnExpression [AS newName]] [,...] }
FROM TableName [alias] [, ...]
[WHEREcondition]
[GROUP BY columnList] [HAVING condition]
[ORDER BY columnList]
FROM Specifies table(s) to be used.
WHERE Filters rows.
GROUP BY Forms groups of rows with same
column value.
HAVING Filters groups subject to some
condition.
SELECT Specifies which columns are to
appear in output.
ORDER BY Specifies the order of the output.
www.bzupages.com
Example 12.1 All Columns, All Rows
13
www.bzupages.com
Example 12.1 All Columns, All Rows
12.1 12.1
14
www.bzupages.com
Example 12.2 Specific Columns, All Rows
Produce a list of salaries for all staff, showing only staff
number, first and last names, and salary.
12.2 12.2
15
www.bzupages.com
Example 12.3 Use of DISTINCT
List the property numbers of all properties that have been viewed.
SELECT PropertyNo
FROM Viewing;
16
www.bzupages.com
Example 12.3 Use of DISTINCT
17
www.bzupages.com
Example 12.4 Calculated Fields
www.bzupages.com
Example 12.4 Calculated Fields
19
www.bzupages.com
Example 12.5 Comparison Search
Condition
List all staff with a salary greater than 10,000.
12.5 12.5
20
www.bzupages.com
In SQL, the following simple comparison operators are available:
= equals
<> is not equal to (ISO standard)
! = is not equal to (allowed in some dialects)
< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to
www.bzupages.com
Example 12.6 Compound Comparison
Search Condition
List addresses of all branch offices in London or Glasgow.
SELECT *
FROM Branch
WHERE city = ‘London’ OR city = ‘Glasgow’;
12.6 12.6
22
www.bzupages.com
Example 12.7 Range Search Condition
23
www.bzupages.com
Example 12.7 Range Search Condition
12.7 12.7
24
www.bzupages.com
Example 12.7 Range Search Condition
25
www.bzupages.com
Example 12.8 Set Membership
List all managers and supervisors.
12.8 12.8
26
www.bzupages.com
Example 12.8 Set Membership
27
www.bzupages.com
Example 12.9 Pattern Matching
12.9 12.9
28
www.bzupages.com
Example 12.9 Pattern Matching
29
www.bzupages.com
Example 12.10 NULL Search Condition
30
www.bzupages.com
Example 12.10 NULL Search Condition
www.bzupages.com
Lecture#13
SQL: Data Manipulation (contd…)
Example 13.1 Single Column Ordering
List salaries for all staff, arranged in descending order of
salary.
13.1 13.1
Example 13.2 Multiple Column Ordering
Produce abbreviated list of properties in order of property type.
13.2 13.2
3
Example 13.2 Multiple Column Ordering
Four flats in this list - as no minor sort key specified, system arranges
these rows in any order it chooses.
To arrange in order of rent, specify minor order:
4
Example 13.2 Multiple Column Ordering
13.2
13.1 13.2
5
SELECT Statement - Aggregates
6
SELECT Statement - Aggregates
7
SELECT Statement - Aggregates
8
Example 13.3 Use of COUNT(*)
How many properties cost more than £350 per month to rent?
column names
aggregate functions
constants
13
SELECT Statement - Grouping
All column names in SELECT list must appear in GROUP BY clause unless
name is used only in an aggregate function.
If WHERE is used with GROUP BY, WHERE is applied first, then groups are
formed from remaining rows satisfying predicate.
ISO considers two nulls to be equal for purposes of GROUP BY.
14
Example 13.7 Use of GROUP BY
Find number of staff in each branch and their total salaries.
SELECT branchNo,
COUNT(staffNo) AS myCount,
SUM(salary) AS mySum
FROM Staff
GROUP BY branchNo
ORDER BY branchNo;
15
Restricted Groupings – HAVING clause
HAVING clause is designed for use with GROUP BY to restrict groups that
appear in final result table.
Similar to WHERE, but WHERE filters individual rows whereas HAVING
filters groups.
Column names in HAVING clause must also appear in the GROUP BY list or
be contained within an aggregate function.
16
Example 13.8 Use of HAVING
For each branch with more than 1 member of staff, find number of
staff in each branch and sum of their salaries.
SELECT branchNo,
COUNT(staffNo) AS myCount,
SUM(salary) AS mySum
FROM Staff
GROUP BY branchNo
HAVING COUNT(staffNo) > 1
ORDER BY branchNo;
17
Example 13.8 Use of HAVING
18
Subqueries
19
Example 13.9 Subquery with Equality
20
Example 13.9 Subquery with Equality
Inner SELECT finds branch number for branch at ‘163 Main St’ (‘B003’).
Outer SELECT then retrieves details of all staff who work at this branch.
Outer SELECT then becomes:
13.9 13.9
21
Example 13.10 Subquery with Aggregate
List all staff whose salary is greater than the average salary, and show by
how much.
22
Example 13.10 Subquery with Aggregate
23
Example 13.10 Subquery with Aggregate
13.10 13.10
24
Subquery Rules
25
Example 13.11 Nested subquery: use of IN
13.11 13.11
27
ANY and ALL
ANY and ALL may be used with subqueries that produce a single column
of numbers.
With ALL, condition will only be true if it is satisfied by all values
produced by subquery.
With ANY, condition will be true if it is satisfied by any values produced
by subquery.
If subquery is empty, ALL returns true, ANY returns false.
SOME may be used in place of ANY.
28
Example 13.12 Use of ANY/SOME
Find staff whose salary is larger than salary of at least one member of
staff at branch B003.
FROM Staff
WHERE salary > SOME
(SELECT salary
FROM Staff
WHERE branchNo = ‘B003’);
29
Example 13.12 Use of ANY/SOME
Inner query produces set {12000, 18000, 24000} and outer query selects
those staff whose salaries are greater than any of the values in this set.
13.12 13.12
30
Example 13.13 Use of ALL
Find staff whose salary is larger than salary of every member of staff at
branch B003.
FROM Staff
WHERE salary > ALL
(SELECT salary
FROM Staff
WHERE branchNo = ‘B003’);
31
Example 13.13 Use of ALL
13.13 13.13
32
Lecture#14
SQL: Data Manipulation (contd…)
Multi-Table Queries
Can use subqueries provided result columns come from same table.
If result columns come from more than one table must use a join.
2
Example 14.1 Simple Join
List names of all clients who have viewed a property along with any
comment supplied.
3
Example 14.1 Simple Join
Only those rows from both tables that have identical values in the
clientNo columns (c.clientNo = v.clientNo) are included in result.
14.1 14.1
4
Alternative JOIN Constructs
In each case, FROM replaces original FROM and WHERE. However, first
produces table with two identical clientNo columns.
5
Example 14.2 Sorting a join
For each branch, list numbers and names of staff who manage
properties, and properties they manage.
6
Example 14.2 Sorting a join
14.2 14.2
7
Example 14.3 Three Table Join
For each branch, list staff who manage properties, including city in which branch
is located and properties they manage.
8
Example 14.3 Three Table Join
14.3 14.3
10
Example 14.4 Multiple Grouping Columns
11
Computing a Join
Procedure for generating results of a join are:
3. For each remaining row, determine value of each item in SELECT list to
produce a single row in result table.
4. If DISTINCT has been specified, eliminate any duplicate rows from the
result table.
13
Outer Joins
The (inner) join of these two tables:
14.5(b)
14
Outer Joins
15
Example 14.6 Left Outer Join
List branches and properties that are in same city along with any
unmatched branches.
16
Example 14.6 Left Outer Join
Includes those rows of first (left) table unmatched with rows from second
(right) table.
Columns from second table are filled with NULLs.
14.6 14.6
17
Example 14.7 Right Outer Join
List branches and properties in same city and any unmatched properties.
18
Example 14.7 Right Outer Join
Right Outer join includes those rows of second (right) table that are
unmatched with rows from first (left) table.
Columns from first table are filled with NULLs.
14.7 14.7
19
Example 14.8 Full Outer Join
List branches and properties in same city and any unmatched branches
or properties.
20
Example 14.8 Full Outer Join
14.8 14.8
21
EXISTS and NOT EXISTS
EXISTS and NOT EXISTS are for use only with subqueries.
True if and only if there exists at least one row in result table returned
by subquery.
(SELECT * ...)
22
Example 14.9 Query using EXISTS
23
Example 14.9 Query using EXISTS
14.9 14.9
24
Example 14.9 Query using EXISTS
25
Example 14.9 Query using EXISTS
26
Union, Intersect, and Difference (Except)
27
Union, Intersect, and Difference (Except)
28
Union, Intersect, and Difference (Except)
29
Example 14.10 Use of UNION
(SELECT city
FROM Branch
WHERE city IS NOT NULL) UNION
(SELECT city
FROM PropertyForRent
WHERE city IS NOT NULL);
30
Example 14.10 Use of UNION
Or
(SELECT *
FROM Branch
WHERE city IS NOT NULL)
UNION CORRESPONDING BY city
(SELECT *
FROM PropertyForRent
WHERE city IS NOT NULL);
31
Example 14.10 Use of UNION
Produces result tables from both queries and merges both tables
together.
14.10 14.10
32
Example 14.11 Use of INTERSECT
List all cities where there is both a branch office and a property.
33
Example 14.11 Use of INTERSECT
Or
14.11 14.11
34
Example 14.11 Use of INTERSECT
SELECT b.city
FROM Branch b PropertyForRent p
WHERE b.city = p.city;
Or:
SELECT DISTINCT city FROM Branch b
WHERE EXISTS
(SELECT * FROM PropertyForRent p
WHERE p.city = b.city);
35
Example 14.12 Use of EXCEPT
36
Example 14.13 Use of EXCEPT
37
INSERT
38
INSERT
39
Example 14.14 INSERT … VALUES
Insert a new row into Staff table supplying data for all columns.
40
Example 14.15 INSERT using Defaults
Insert a new row into Staff table supplying data for all mandatory
columns.
41
INSERT … SELECT
42
Example 14.16 INSERT … SELECT
43
Example 14.16 INSERT … SELECT
45
UPDATE
UPDATE TableName
SET columnName1 = dataValue1
[, columnName2 = dataValue2...]
[WHERE searchCondition]
46
UPDATE
47
Example 14.17/18 UPDATE All Rows
UPDATE Staff
SET salary = salary*1.03;
UPDATE Staff
SET salary = salary*1.05
WHERE position = ‘Manager’;
48
Example 14.19 UPDATE Multiple Columns
UPDATE Staff
SET position = ‘Manager’, salary = 18000
WHERE staffNo = ‘SG14’;
49
DELETE
50
Example 14.20/21 DELETE Specific Rows
51
Lecture #15
SQL: Data Definition
ISO SQL Data Types
Integrity Enhancement Feature
Integrity constraints:
required data
domain constraints
entity integrity
referential integrity
general constraints.
Integrity Enhancement Feature
Required Data
position VARCHAR(10) NOT NULL
Domain Constraints
(a) CHECK
sex CHAR NOT NULL
CHECK (sex IN (‘M’, ‘F’))
Integrity Enhancement Feature
SQL DDL allows database objects such as schemas, domains, tables, views, and
indexes to be created and destroyed
Main SQL DDL statements:
Virtual relation that does not necessarily actually exist in database but is
produced upon request, at time of request
Contents of a view are defined as query on one or more base relations
View resolution
Any operations on view automatically translated into operations on
relations from which derived
View materialization
View stored as temporary table
Maintained as underlying base tables are updated
SQL - CREATE VIEW
Create view so that manager at branch B003 can only see details for staff who work in
his or her office.
With CASCADE
All related dependent objects deleted; i.e. any views defined on
view being dropped.
With RESTRICT (default)
If any other objects depend for existence on continued existence
of view being dropped → command rejected
View Resolution
(a) View column names in SELECT list are translated into corresponding
column names in defining query:
(c) WHERE from user query combined with WHERE of defining query using
AND:
ORDER BY s.staffNo
View Resolution
SELECT COUNT(cnt)
FROM StaffPropCnt;
SELECT *
FROM StaffPropCnt
WHERE cnt > 2;
Restrictions on Views
(b) Grouped view may never be joined with base
table or view
For example
StaffPropCnt view is grouped view, any attempt
to join this view with another table or view fails
View Updatability
This update would fail: although update would cause row to disappear from
HighSalary, row would not disappear from LowSalary
If update tried to set salary to 8000, update would succeed as row would no
longer be part of LowSalary
Example 16.4 - WITH CHECK OPTION
Data independence
Currency
Improved security
Reduced complexity
Convenience
Customization
Data integrity
Disadvantages of Views
Update restriction
Structure restriction
Performance
View Materialization
34
View Materialization
If insert row into PropertyForRent with rent 400
then view would be unchanged
If insert row for property PG24 at branch B003 with
staffNo = SG19 and rent = 550, then row would
appear in materialized view
If insert row for property PG54 at branch B003 with
staffNo = SG37 and rent = 450, then no new row
would need to be added to materialized view
If delete property PG24, row should be deleted from
materialized view
If delete property PG54, then row for PG37 should
not be deleted (because of existing property PG21)
Granting Privileges to Other Users(GRANT)
SQL GRANT is a command used to provide access or privileges on the database
objects to other users.
The format of the GRANT statement is:
GRANT {PrivilegeList | ALL PRIVILEGES}
ON ObjectName
TO {AuthorizationIdList | PUBLIC}
[WITH GRANT OPTION]
PrivilegeList consists of one or more of the following privileges separated by
commas:
SELECT
DELETE
INSERT [(columnName [, . . . ])]
UPDATE [(columnName [, . . . ])]
REFERENCES [(columnName [, . . . ])]
USAGE
For convenience, the GRANT statement allows the keyword ALL
PRIVILEGES to be used to grant all privileges to a user instead of
having to specify the six privileges individually.
GRANT SELECT
ON Branch
TO PUBLIC;
Revoking Privileges From Users(REVOKE)
The REVOKE statement is used to take away privileges that were
granted with the GRANT statement. A REVOKE statement can take
away all or some of the privileges that were previously granted to a
user.
The format of the statement is:
REVOKE [GRANT OPTION FOR] {PrivilegeList | ALL PRIVILEGES}
ON ObjectName
FROM {AuthorizationIdList | PUBLIC} [RESTRICT | CASCADE]
The keyword ALL PRIVILEGES refers to all the privileges granted to
a user by the user revoking the privileges. The optional GRANT
OPTION FOR clause allows privileges passed on via the WITH GRANT
OPTION of the GRANT statement to be revoked separately from the
privileges themselves.
The RESTRICT and CASCADE qualifiers operate exactly as in the
DROP TABLE statement.
Since privileges are required to create certain objects, revoking a
privilege can remove the authority that allowed the object to be
created (such an object is said to be abandoned).
The REVOKE statement fails if it results in an abandoned object,
such as a view, unless the CASCADE keyword has been specified.
If CASCADE is specified, an appropriate DROP statement is issued
for any abandoned views, domains, constraints, or assertions
Example 16.8 REVOKE specific privileges from
PUBLIC
Revoke the privilege SELECT on the Branch table from all users.
REVOKE SELECT
ON Branch
FROM PUBLIC;
Example 16.9 REVOKE specific privileges from
named user
Revoke all privileges you have given to Director on the Staff table.
www.bzupages.com
Objectives
2
www.bzupages.com
ER diagram of Branch user views of
DreamHome
3
www.bzupages.com
Concepts of the ER Model
Entity types
Relationship types
Attributes
4
www.bzupages.com
Entity Type
Entity type
Group of objects with same properties, identified by enterprise as
having an independent existence.
Entity occurrence
Uniquely identifiable object of an entity type.
5
www.bzupages.com
Examples of Entity Types
6
www.bzupages.com
ER diagram of Staff and Branch
entity types
7
www.bzupages.com
Relationship Types
Relationship type
Set of meaningful associations among entity types.
Relationship occurrence
Uniquely identifiable association, which includes one occurrence from each
participating entity type.
8
www.bzupages.com
Semantic net of Has relationship type
9
www.bzupages.com
ER diagram of Branch Has Staff
relationship
10
www.bzupages.com
Relationship Types
Degree of a Relationship
Number of participating entities in relationship.
Relationship of degree :
two is binary
three is ternary
four is quaternary.
11
www.bzupages.com
Binary relationship called POwns
12
www.bzupages.com
Ternary relationship called Registers
13
www.bzupages.com
Quaternary relationship called Arranges
14
www.bzupages.com
Relationship Types
Recursive Relationship
Relationship type where same entity type participates more than once in
different roles.
15
www.bzupages.com
Recursive relationship called
Supervises with role names
16
www.bzupages.com
Entities associated through two distinct
relationships with role names
17
www.bzupages.com
Attributes
Attribute
Property of an entity or a relationship type.
Attribute Domain
Set of allowable values for one or more attributes.
18
www.bzupages.com
Attributes
Simple Attribute
Attribute composed of a single component with an
independent existence.
Composite Attribute
Attribute composed of multiple components, each with an
independent existence.
19
www.bzupages.com
Attributes
Single-valued Attribute
Attribute that holds a single value for each occurrence of
an entity type.
Multi-valued Attribute
Attribute that holds multiple values for each occurrence of
an entity type.
20
www.bzupages.com
Attributes
Derived Attribute
Attribute that represents a value that is derivable from value of a related
attribute, or set of attributes, not necessarily in the same entity type.
21
www.bzupages.com
Keys
Candidate Key
Minimal set of attributes that uniquely identifies each
occurrence of an entity type.
Primary Key
Candidate key selected to uniquely identify each occurrence
of an entity type.
Composite Key
A candidate key that consists of two or more attributes.
22
www.bzupages.com
ER diagram of Staff and Branch entities
and their attributes
23
www.bzupages.com
Entity Type
24
www.bzupages.com
Strong entity type called Client and weak
entity type called Preference
25
www.bzupages.com
Relationship called Advertises with attributes
26
www.bzupages.com
Lecture #18
Entity-Relationship modelling (contd..)
Structural Constraints
2
Structural Constraints
3
Semantic net of Staff Manages Branch
relationship type
4
Multiplicity of Staff Manages Branch
(1:1) relationship
5
Semantic net of Staff Oversees
PropertyForRent relationship type
6
Multiplicity of Staff Oversees PropertyForRent
(1:*) relationship type
7
Semantic net of Newspaper Advertises
PropertyForRent relationship type
8
Multiplicity of Newspaper Advertises
PropertyForRent (*:*) relationship
9
Structural Constraints
10
Semantic net of ternary Registers relationship
with values for Staff and Branch entities fixed
11
Multiplicity of ternary Registers relationship
12
Summary of multiplicity constraints
13
Structural Constraints
Cardinality
Describes maximum number of possible relationship occurrences for an
entity participating in a given relationship type.
Participation
Determines whether all or only some entity occurrences participate in a
relationship.
14
Multiplicity as cardinality and participation
constraints
15
Problems with ER Models
Two main types of connection traps are called fan traps and chasm
traps.
16
Problems with ER Models
Fan Trap
Where a model represents a relationship between entity types, but
pathway between certain entity occurrences is ambiguous.
Chasm Trap
Where a model suggests the existence of a relationship between
entity types, but pathway does not exist between certain entity
occurrences.
17
An Example of a Fan Trap
18
Semantic Net of ER Model with Fan Trap
20
Semantic Net of Restructured ER Model
with Fan Trap Removed
21
An Example of a Chasm Trap
22
Semantic Net of ER Model with Chasm Trap
23
ER Model restructured to remove Chasm Trap
24
Semantic Net of Restructured ER Model
with Chasm Trap Removed
25
Lecture#19
Enhanced Entity-Relationship Modeling
Objectives
Limitations of basic concepts of the ER model and requirements to
represent more complex applications using additional data modeling
concepts.
Superclass
An entity type that includes one or more distinct subgroupings of its
occurrences.
Subclass
A distinct subgrouping of occurrences of an entity type.
Specialization / Generalization
6
AllStaff Relation Holding Details of all
Staff
7
Specialization / Generalization
Attribute Inheritance
An entity in a subclass represents same ‘real world’
object as in superclass, and may possess subclass-
specific attributes, as well as those associated with the
superclass.
Specialization / Generalization
Specialization
Process of maximizing differences between members of an
entity by identifying their distinguishing characteristics.
Generalization
Process of minimizing differences between entities by
identifying their common characteristics.
Specialization/Generalization of Staff Entity
into Subclasses Representing Job Roles
Specialization/Generalization of Staff Entity into
Job Roles and Contracts of Employment
EER Diagram with Shared Subclass and
Subclass with its own Subclass
Constraints on Specialization / Generalization
disjoint constraints.
Participation constraint
Determines whether every member in superclass
must participate as a member of a subclass.
May be mandatory or optional.
Constraints on Specialization /
Generalization
Disjoint constraint
Describes relationship between members of the
subclasses and indicates whether member of a
superclass can be a member of one, or more
than one, subclass.
May be disjoint or nondisjoint.
Constraints on Specialization /
Generalization
There are four categories of constraints of specialization and
generalization:
mandatory and disjoint;
optional and disjoint;
mandatory and nondisjoint;
optional and nondisjoint.
DreamHome Worked Example - Staff Superclass with
Supervisor and Manager Subclasses
DreamHome Worked Example - Owner Superclass
with PrivateOwner and BusinessOwner Subclasses
DreamHome Worked Example - Person Superclass with
Staff, PrivateOwner, and Client Subclasses
EER Diagram of Branch View of DreamHome with
Specialization/Generalization
Aggregation
Represents a ‘has-a’ or ‘is-part-of’ relationship
between entity types, where one represents the
‘whole’ and the other ‘the part’.
Examples of Aggregation
Composition
9
Data Redundancy and Update Anomalies
StaffBranch relation has redundant data; the details of a branch are
repeated for every member of staff.
In contrast, the branch information appears only once for each branch in
the Branch relation and only the branch number (branchNo) is repeated in
the Staff relation, to represent where each member of staff is located.
Data Redundancy and Update Anomalies
12
Lossless-join and Dependency
Preservation Properties
Two important properties of decomposition.
Lossless-join property enables us to find any instance of the
original relation from corresponding instances in the smaller
relations.
Dependency preservation property enables us to enforce a
constraint on the original relation by enforcing some constraint
on each of the smaller relations.
Functional Dependencies
Important concept associated with normalization.
Diagrammatic representation.
Consider the values shown in staffNo and sName attributes of the Staff
relation.
staffNo → sName
sName → staffNo
Example Functional Dependency that
holds for all Time
However, the only functional dependency that remains true for all
possible values for the staffNo and sName attributes of the Staff
relation is:
staffNo → sName
Characteristics of Functional Dependencies
A→C (fd1)
C→A (fd2)
B →D (fd3)
A, B → E (fd4)
B, C → E (fd5)
Identifying the Primary Key for a
Relation using Functional Dependencies
Main purpose of identifying a set of functional dependencies for a
relation is to specify the set of integrity constraints that must hold
on a relation.
A→C (fd1)
C→A (fd2)
B →D (fd3)
A, B → E (fd4)
B, C → E (fd5)
To identify all candidate key(s), identify the attribute (or group of attributes)
that uniquely identifies each tuple in this relation.
The Process of Normalization
As normalization proceeds, the relations become progressively more
restricted (stronger) in format and also less vulnerable to update
anomalies.
The Process of Normalization
Unnormalized Form (UNF)
A relation in which the intersection of each row and column contains one
and only one value.
11
UNF to 1NF
Nominate an attribute or group of attributes to act as the key for the
unnormalized table.
Identify the repeating group(s) in the unnormalized table which repeats for the
key attribute(s).
UNF to 1NF
Remove the repeating group by
Entering appropriate data into the empty columns of rows containing the repeating
data (‘flattening’ the table).
Or by
Placing the repeating data along with a copy of the original key attribute(s) into a
separate relation.
Second Normal Form (2NF)
Whereas, BCNF insists that for this dependency to remain in a relation, A must be a
candidate key.
Every relation in BCNF is also in 3NF. However, relation in 3NF may not be in BCNF.
Boyce–Codd normal form (BCNF)
Violation of BCNF is quite rare.
DreamHome
Lecture#22
Normalization (contd…)
Review of Normalization (UNF to BCNF)
DreamHome
Review of Normalization (UNF to BCNF)
1)Repeating Group =
(iDate,iTime,comments,staffNo,sName,carReg)
3)UNF
First Normal Form (1NF)
•(propertyNo, iDate)
• (carReg,iDate,iTime)
• (staffNo, iDate, iTime)
First Normal Form (1NF)
1NF
StaffPropertyInspection
( propertyNo,iDate,iTime,pAddress,comments,staffNo,sName,carReg )5
Second Normal Form (2NF)
Second Normal Form (2NF)
The functional dependencies (fd1 to fd6) of the StaffPropertyInspection relation are as follows:
fd1 propertyNo, iDate → iTime, comments, staffNo, sName, carReg (Primary key)
fd2 propertyNo → pAddress (Partial dependency)
fd3 staffNo → sName (Transitive dependency)
fd4 staffNo, iDate → carReg
fd5 carReg, iDate, iTime → propertyNo, pAddress, comments, staffNo, sName (Candidate key)
fd6 staffNo, iDate, iTime → propertyNo, pAddress, comments (Candidate key)
Review of Normalization (UNF to BCNF)
1NF
StaffPropertyInspection
( propertyNo,iDate,iTime,pAddress,comments,staffNo,sName,carReg )
2NF
Property
( propertyNo,pAddress )
PropertyInspection
( propertyNo,iDate,iTime,comments,staffNo,sName,carReg )
THIRD Normal Form (3NF)
PropertyInspection
( propertyNo,iDate,iTime,comments,staffNo,sName,carReg )
3NF
Property ( propertyNo,pAddress )
PropertyInspect
( propertyNo,iDate,iTime,comments,staffNo,carReg )
Boyce-Codd Normal Form (BCNF)
The functional dependencies for the Property, Staff, and PropertyInspect
relations are as follows:
Property Relation
fd2 propertyNo → pAddress
Staff Relation
fd3 staffNo → sName
PropertyInspect Relation
fd1′ propertyNo, iDate → iTime, comments, staffNo, carReg
fd4 staffNo, iDate → carReg
fd5′ carReg, iDate, iTime → propertyNo, comments, staffNo
fd6′ staffNo, iDate, iTime → propertyNo, comments
Boyce-Codd Normal Form (BCNF)
BCNF
Property ( propertyNo,pAddress )
Staff ( staffNo,sName )
Inspection
( propertyNo,iDate,iTime,comments,staffNo )
Review of Normalization (UNF to BCNF)
Lecture#23
Database Security
Objectives
The scope of database security.
6
Summary of Threats to Computer
Systems
7
Typical Multi-user Computer
Environment
Countermeasures – Computer-Based
Controls
Concerned with physical controls to administrative
procedures and includes:
Authorization
Access controls
Views
Backup and recovery
Integrity
Encryption
RAID technology
Countermeasures – Computer-Based
Controls
Authorization
The granting of a right or privilege, which enables a subject to
legitimately have access to a system or a system’s object.
Authentication is a mechanism that determines whether a user
is, who he or she claims to be.
Countermeasures – Computer-Based
Controls
Access control
Based on the granting and revoking of privileges.
A privilege allows a user to create or access (that is read, write,
or modify) some database object (such as a relation, view, and
index) or to run certain DBMS utilities.
Privileges are granted to users to accomplish the tasks required
for their jobs.
Countermeasures – Computer-Based
Controls
Most DBMS provide an approach called Discretionary Access
Control (DAC).
View
Is the dynamic result of one or more relational operations operating
on the base relations to produce another relation.
A view is a virtual relation that does not actually exist in the
database, but is produced upon request by a particular user, at the
time of request.
Countermeasures – Computer-Based
Controls
Backup
Process of periodically taking a copy of the database and log file (and
possibly programs) to offline storage media.
Journaling
Process of keeping and maintaining a log file (or journal) of all changes
made to database to enable effective recovery in event of failure.
Lecture#24
Database Security(contd…)
Objectives
2
Countermeasures – Computer-Based
Controls
Integrity
Prevents data from becoming invalid, and hence giving misleading or
incorrect results.
Encryption
The encoding of the data by a special algorithm that renders the data
unreadable by any program without the decryption key.
To transmit data securely over insecure networks requires the use of a
cryptosystem, which includes:
An an encryption key to encrypt the data (plaintext);
An encryption algorithm that, with the encryption key, transforms the
plaintext into ciphertext;
A decryption key to decrypt the ciphertext;
A decryption algorithm that, with the decryption key, transforms the
ciphertext back into plaintext.
One technique, called symmetric encryption, uses the same key for both
encryption and decryption and relies on safe communication lines for
exchanging the key.
However, most users do not have access to a secure communication line and, to
be really secure, the keys need to be as long as the message .
However, most working systems are based on user keys shorter than the
message.
One scheme used for encryption is the Data Encryption Standard (DES), which is
a standard encryption algorithm developed by IBM.
RAID (Redundant Array of Independent
Disks) Technology
Hardware that the DBMS is running on must be fault-tolerant, meaning that the
DBMS should continue to operate even if one of the hardware components fails.
Disk drives are the most vulnerable components with the shortest times
between failure of any of the hardware components.
RAID (Redundant Array of Independent
Disks) Technology
One solution is to provide a large disk array comprising an arrangement of
several independent disks that are organized to improve reliability and at
the same time increase performance.
RAID (Redundant Array of Independent
Disks) Technology
Performance is increased through data striping: the data is segmented
into equal-size partitions (the striping unit), which are transparently
distributed across multiple disks.
1
Objectives
2
Chapter 19 - Objectives
Recovery Control
Some causes of database failure.
Purpose of transaction log file.
Purpose of checkpointing.
How to recover following database failure.
Alternative models for long duration transactions.
3
Transaction Support
Transaction
Action, or series of actions, carried out by user
or application, which accesses or changes
contents of database.
Logical unit of work on the database.
Application program is series of transactions with
non-database processing in between.
Transforms database from one consistent state to
another, although consistency may be violated
during transaction.
4
Example Transaction
5
Transaction Support
6
State Transition Diagram for
Transaction
7
Properties of Transactions
8
DBMS Transaction Subsystem
9
Concurrency Control
10
Need for Concurrency Control
11
Lecture 26
Transaction Management(contd..)
1
Lost Update Problem
2
Lost Update Problem
3
Uncommitted Dependency Problem
4
Uncommitted Dependency Problem
5
Inconsistent Analysis Problem
6
Inconsistent Analysis Problem
8
Serializability
Schedule
Sequence of reads/writes by set of concurrent transactions.
Serial Schedule
Schedule where operations of each transaction are executed
consecutively without any interleaved operations from other transactions.
9
Nonserial Schedule
10
Serializability
11
Example of Conflict Serializability
12
Serializability
13
Precedence Graph
Create:
node for each transaction;
a directed edge Ti → Tj, if Tj reads the value of an item written by TI;
a directed edge Ti → Tj, if Tj writes a value into an item after it has been
read by Ti.
If precedence graph contains cycle schedule is not conflict
serializable.
14
Example - Non-conflict serializable schedule
15
Example - Non-conflict serializable schedule
16
View Serializability
Offers less stringent definition of schedule equivalence than conflict
serializability.
Two schedules S1 and S2 are view equivalent if:
For each data item x, if Ti reads initial value
of x in S1, Ti must also read initial value of x
in S2.
For each read on x by Ti in S1, if value read
by x is written by Tj, Ti must also read value
of x produced by Tj in S2.
For each data item x, if last write on x
performed by Ti in S1, same transaction must
perform final write on x in S2.
17
View Serializability
18
Example - View Serializable schedule
19
Lecture 27
Transaction Management(contd..)
1
Recoverability
2
Recoverable Schedule
3
Concurrency Control Techniques
4
Locking
5
Locking - Basic Rules
If transaction has shared lock on item, can read but not update item.
If transaction has exclusive lock on item, can both read and update
item.
Reads cannot conflict, so more than one transaction can hold shared
locks simultaneously on same item.
Exclusive lock gives transaction exclusive access to that item.
6
Locking - Basic Rules
7
Example - Incorrect Locking Schedule
For two transactions above, a valid schedule using these rules is:
8
Example - Incorrect Locking Schedule
9
Example - Incorrect Locking Schedule
10
Two-Phase Locking (2PL)
11
Preventing Lost Update Problem using 2PL
12
Preventing Uncommitted Dependency Problem
using 2PL
13
Preventing Inconsistent Analysis Problem using
2PL
14
Cascading Rollback
15
Cascading Rollback
16
Cascading Rollback
17