CH 2 Database Systems
CH 2 Database Systems
1
Learning Outcomes
2
1. Disadvantages of File Processing
(Traditional Approach)
• Program-Data Dependence (See slide 5)
– All programs maintain metadata for each file they use
• Data Redundancy (Duplication of data) (See slide 6)
– Different systems/programs have separate copies of the same
data
• Limited Data Sharing
– No centralized control of data
• Lengthy Development Times
– Programmers must design their own file formats
• Excessive Program Maintenance
– 80% of the information systems budget
3
Example : Three file processing systems
Duplicate
Data
Program-Data Dependence
Data Redundancy (duplication of data)
Limited Data Sharing
Lengthy Development Times
Excessive Program Maintenance 4
Problems with Data Dependency
Each application programmer
must maintain their own data
Each application program
needs to include code for the
metadata of each file
Each application program
must have its own processing
routines for reading, inserting,
updating and deleting data
Lack of coordination and
central control
Non-standard file formats
5
Problems with Data Redundancy
• Waste of space to have duplicate data
• Causes more maintenance headaches
• The biggest Problem:
– When data changes in one file, could cause
inconsistencies
– Compromises data integrity
6
2. Database Management System (DBMS)
• A software system that enables users to define,
create, maintain, and control access to the database.
7
2.1 Functions of a DBMS
• Store, Update and Retrieve Data
8
Effect of no concurrency control
E.g. Two customers withdrawing funds from the same
account at the same time - account has $1000 in it, and they
withdraw $200 and $300.
9
9
Functions of a DBMS
•Backup and Recovery Services.
Crash, fire, natural disaster
So data not permanently lost
10
Functions of a DBMS
Security
Prevent unauthorized users accessing the database.
Encryption, authentication, authorization and views
11
Functions of a DBMS
• Integrity Services.
Avoid incorrect or inconsistent data by complying
a set of rules to ensure data integrity is enforced.
CREATE TABLE PropertyForRent(
propertyNo VARCHAR(5) NOT NULL,
rent NUMBER NOT NULL DEFAULT 600,
staffNo VARCHAR(5)
CONSTRAINT StaffNotHandlingTooMuch
CHECK (NOT EXISTS (SELECT staffNo
FROM PropertyForRent
GROUP BY staffNO
HAVING COUNT(*) > 100)),
PRIMARY KEY (propertyNo),
FOREIGN KEY (staffNo) REFERENCES Staff
12
Types Of Integrity Constraint In Oracle
• A NOT NULL constraint prohibits a database value from being null.
• A unique constraint prohibits multiple rows from having the same
value in the same column or combination of columns but allows
some values to be null.
• A primary key constraint combines a NOT NULL constraint and a
unique constraint in a single declaration.
• A foreign key constraint requires values in one table to match
values in another table.
• A check constraint requires a value in the database to comply with
a specified condition.
– CHECK (supplier_id BETWEEN 100 and 9999)
– CHECK (supplier_name IN ('IBM', 'Microsoft', 'NVIDIA')
– CHECK (status NOT IN ('A','B','C','D'));
13
CREATE TABLE OrderDetail (
OrderDetailKey VARCHAR(10) NOT NULL,
OrderKey VARCHAR(10),
ProductKey VARCHAR(10),
Quantity NUMBER(3) check (Quantity >=1),
PriceCharged NUMBER(6,2) check (PriceCharged > 0),
constraint OrderToOrddet unique (OrderKey, ProductKey),
Primary key (OrderDetailKey),
Foreign Key (OrderKey) references CustomerOrder(OrderKey),
Foreign Key (ProductKey) references Product (ProductKey)
);
14
14
• Transaction Support
Ensure that all the updates are made or that none
of them is made.
Airline Transaction Example
1. BEGIN-TRANS
2. Display greeting
3. Get reservation preferences from user
4. SELECT departure and return flight records
5. If reservation is acceptable then
6. UPDATE seats remaining of departure flight record
7. UPDATE seats remaining of return flight record
8. INSERT reservation record
9. Print ticket if requested
10. End If
11. On Error: ROLLBACK 15
Functions of a DBMS
• A User-Accessible System Catalogue
(Data Dictionary Management).
• System Catalogue
• Repository of information (metadata) describing the data in
the database.
• One of the fundamental components of DBMS.
• Typically stores:
names, types, and sizes of data items;
constraints on the data;
names of authorized users;
data items accessible by a user and the type of access;
usage statistics (eg counts on the number of accesses
made to objects in the database)
16
DBMS consults the
system catalog
before performing
almost every
action:
• Authorize users
• Process queries
• Check integrity
• etc
17
Sample Oracle Catalog Tables
Table Name Contents
USER_CATALOG Contains basic data about each table and view defined by
a user.
USER_OBJECTS Contains data about each object (functions, procedures,
indexes, triggers, assertions, etc.) defined by a user. This
table contains the time created and the last time changed
for each object.
USER_TABLES Contains extended data about each table such as space
allocation and statistical summaries.
USER_TAB_COLUMNS Contains basic and extended data for each column such as
the column name, the table reference, the data type, and a
statistical summary.
USER_VIEWS Contains the SQL statement defining each view.
18
Oracle Metadata
19
2.2 Components of a DBMS
• A DBMS is
partitioned into
several software
components (or
modules), each of
which is assigned a
specific operation.
• The DBMS
interfaces with
other software
components, such
as user queries and
access methods.
20
20
Components of a DBMS
• Query processor - transforms queries into low-level
instructions directed to the database manager.
• Database manager
• DML preprocessor converts DML statements embedded in
an application program into standard function calls in the
host language.
21
21
Components of a DBMS
• DDL compiler
converts DDL
statements into a
set of tables
containing
metadata. These Catalog
tables are then manager
stored in the
system catalog
• Catalog manager
manages access to
and maintains the
system catalog. 22
22
Components of Database Manager
• Authorization control.
• Command processor
• Integrity checker
• Query optimizer determines an
optimal strategy for the query
execution.
• Transaction manager
• Scheduler ensures concurrent
operations proceed without
conflicting with one another.
Recovery manager
• Buffer manager responsible for
the transfer of data between
main memory and secondary
storage, such as disk and tape.
23
23
3. ANSI-SPARC Architecture
26
Objectives of Three-Level Architecture
• Internal structure of
database should be
unaffected by changes to
physical aspects of storage.
31
31
Teleprocessing
• One computer with a single CPU and a number of
terminals.
• Processing performed within the same physical
computer. User terminals are typically “dumb”,
incapable of functioning on their own, and cabled
to the central computer.
32
32
File-Server Architecture
• File-server is connected to
several workstations across
a network.
• Database resides on file-
server.
• DBMS and applications run
on each workstation.
33
File-Server Architecture
Disadvantages :
• Significant network traffic.
• Copy of DBMS on each
workstation.
• Concurrency, recovery and
integrity control more complex
(multiple DBMSs accessing the
same files.)
34
Traditional Two-Tier Client-Server
• Client (tier 1) manages user interface and runs
applications.
• Server (tier 2) holds database and DBMS.
35
Summary of Client-Server Functions
36
36
Three-Tier Client-Server
• 2-tier architecture presented two
problems preventing true
scalability:
– ‘Fat’ client, requiring
considerable resources on
client’s computer to run
effectively.
– Significant client side
administration overhead.
37
Three-Tier Client-Server
• Advantages
– ‘Thin’ client, requiring less
expensive hardware.
– Application maintenance
centralized.
– Easier to modify or replace one
tier without affecting others.
– Separating business logic from
database functions makes it
easier to implement load
balancing.
– Maps quite naturally to Web
environment. 38
Modern Database Management, Hoffer 39
N-Tier Client-Server Architectures
• The three-tier
architecture can be
expanded to n tiers, with
additional tiers providing
more flexibility and
scalability.
• Applications servers host
API to expose business
logic and business
processes for use by other
applications.
40
40
Transaction Processing Monitors
• Forms the middle tier of
a three-tier architecture
• 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).
41
How TP Monitor provides for consistent environment?
42
How TP Monitor provides for consistent environment?
43
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.
• Distributed DBMS
permits the management
of the distributed
database and makes the
distribution transparent 44
to users. 44
References
• Database Systems: A Practical Approach to
Design, Implementation and Management.
Connolly, T. M. and Begg, C. E. .
• Modern Database Management.Hoffer, J.A.,
Prescott, M., and McFadden,F.
• Database System Concepts . Silberschatz, A.,
Korth, H,. and Sudarshan, S.
• Fundamentals of Database Systems.
Elmasri, R. and Navathe, S.B.
45
45