0% found this document useful (0 votes)
41 views50 pages

DB2 Concepts

This document provides an overview of DB2 concepts including: - The DB2 family of products and their components for accessing and managing data - Key DB2 objects like databases, tables, and indexes - Methods for connecting to and accessing data in DB2 databases including static and dynamic SQL, programming interfaces, and tools - Features that enable distributed data access and management across platforms like stored procedures and user-defined functions

Uploaded by

Unknown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views50 pages

DB2 Concepts

This document provides an overview of DB2 concepts including: - The DB2 family of products and their components for accessing and managing data - Key DB2 objects like databases, tables, and indexes - Methods for connecting to and accessing data in DB2 databases including static and dynamic SQL, programming interfaces, and tools - Features that enable distributed data access and management across platforms like stored procedures and user-defined functions

Uploaded by

Unknown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Welcome to:

DB2 Concepts

2.1
Unit Objectives

After completing this unit, you should be able to:


Identify DB2 family products
Explain DB2 workstation component functions
Identify DB2 objects
Discuss the concepts of relational tables and DB2's
implementation of referential integrity
Define a unit of recovery and detail the basic locking
strategies used by DB2
Identify the key differences between static SQL and
other application alternatives for accessing DB2 data
Identify DB2's role in X/OPEN
DB2 Family
UNIX Systems Intel Systems

DB2 DB2

DB2 for
OS/390

DB2 for
DB2 for OS/400
S/390, S/370 VSE and VM

AS/400
DB2 Product Components

DRDA Application
Administration Run-Time
Application Development
Client Client
Requester Client

Communication Support

DB2 DB2 Connect

DB2 Relational Connect


(EE or EEE)
DRDA Application Server

Oracle Database
Connecting to DB2 UDB Database Servers
DB2 Personal Developer's Edition (PDE) includes:

DB2
Personal Run-Time Client
Edition includes:

DB2 Connect Workgroup


Personal Server
Edition Edition
ODBC Command
support Line
Application Processor
Development (CLP)
Client
Enterprise
Server
JDBC Edition
Administration support
Client

Extenders
Netscape Communicator
DB2 Product Information
Accessing DB2
Command Line Administration
Applications
Processor Tools
APIs
Control Center
Commands Embedded
Command Center
SQL
Interactive Task Center
SQL Call Level
Development Center Interface
Journal
Event Analyzer JAVA

Health Center

SQL/API

Database Engine
End-User Access
END USER
Application
Analyst

Application Query
Programmer (I/C Consultant)
Tool

DBA

Systems DATA
Programmer BASE
What's in an Instance?
DB2 Product

INSTANCE_1 INSTANCE_2
CATALOG CATALOG
DB DB
DB_1 CONFIG DB_3 CONFIG
LOG
FILE_1 LOG FILE_3

JOIN
(federated)

CATALOG CATALOG
DB DB
DB_2 CONFIG DB_4 CONFIG
LOG
FILE_2 LOG
FILE_4

DBM CONFIG FILE_1 DBM CONFIG FILE_2


Connect to Database

Application Application
Requestor Server

CONNECT TO dbname
USER userid USING password database
DB2 Object Hierarchy

Instance 1 dbm configuration file

Catalog Catalog

Database 1 Log Database 2 Log

DB configuration file DB config. file

Table1 Table2 Table3 Table2

Index1 View1
View1 Index1

BLOBs View2 Index2

View3
VIEW

BASE TABLE VIEW


AS IT EXISTS AS THE PROGRAM's
ON STORAGE LOGIC SEES IT

A B C D B C
Application Alternatives
Static SQL
Dynamic SQL
Perl
Call Level Interface
ODBC

OLE DB
Java Development
JDBC and SQLJ

Stored Procedures
User-Defined Functions
Application Programming Interfaces (APIs)
Distributed Transaction Processing
Static Embedded SQL

Source code with SQL

Table/Column Descriptions

Authorizations
PREPARE
Statistics

Package

Package: Contains SQL statements optimized


according to database statistics
Static SQL

Vacation Travel Booking

Vacation Code: Travel Date:


Origination:

Name:
Charge Card: Exp. Date:
Telephone:

SQL statements prepared during application development


Dynamic SQL

Vacation Travel Unlimited

Type: Date:
Destination:
Country: State:
Language:
Activities:
Cooking, Laundry, Household:
Number Traveling:
Mode of Transportation:
Cost:

SQL statements prepared during application execution


Programming in Perl

Perl is an interpreted language

All SQL is processed dynamically

DBD::DB2 driver available from


http://www.ibm.com/db2/perl

Perl Database Interface (DBI) Module available


from http://www.perl.com
CLI/ODBC

CLI/ODBC versus Dynamic

. EXEC SQL PREPARE ...


SQLPrepare(...);
EXEC SQL EXECUTE ...
...

SQLExecute(...);
SQL statements EXEC SQL FETCH ...
...

prepared during
SQLFetch(...); application execution
..

Prepare Prepare

Execute DB2 or Execute


Other DB2
RDBMS
Heterogeneous Data Access - OLE DB

OLE DB Consumer and Provider Support (Windows Only)

Ability to use any OLE DB data source as a Read Only


DB2 table

Ability for OLE DB-based applications to extract or query


DB2 data using the native OLE interface

DB2 parameters
client DB2
DB2 OLEDB
OLE DB OLE DB
DB2 consumer provider
client Source Data

Virtual Table
Java Applications

SQLJ
Application

SQLJ
Run-Time Classes

Remote
Database

Java
JDBC DB2 Client
Application
DB2 Java Applets

Web Browser Web Server Host

HTTPd
SQLJ Applet
JDBC Server Local DB2
SQLJ Run-Time
Classes Database
CLI
HTTP

Java/ TCP/IP
JDBC Socket
JDBC
Client
Applet

Remote DB2
Database
Stored Procedures

Client Run-Time DB2


DB2
Application Client Server
Database

Network

Client Run-Time Stored


Application Client Procedure

DB2
DB2
Server
Database
Stored Procedure Builder
Development of DB2 stored procedures made simple
Supports development and debugging of Java and
SQL PL stored procedures on all DB2 UDB Server
platforms
Supports static (SQLJ) and dynamic (JDBC) SQL
GUI development environment
Users can focus on the logic of their SPs
Wizards simplify many tasks
Tool automates build process
Can be launched from MS Visual Studio and MS Visual
Basic; Integrated with VisualAge for Java

Benefits:
Ease of development
Portability across DB2 family
Stored Procedure Builder Example

Follow steps in Stored


Procedure Builder Wizard
to construct a new Java SP
User-Defined Functions

SELECT EURO(SALARY) FROM EMP

DB2
Server DB2
Database

Functions
EURO
Conversion
Function EURO Convert ! EURO
Database Manager APIs

API -
Start Database Manager
Create Database
Backup Database
Bind
...

SQL -
Select
Insert
Update
...
X/Open XA Support for
Distributed Transaction Processing

Application Program (AP)

(1) (2)

Resource Transaction
Managers Manager
(RMs) (TM)
(3)
Referential Integrity (1 of 3)
Some Basic Terms
PRIMARY
KEY

DEPTNO DEPTNAME ....


Parent ... ........ ....
Table C01 INFORMATION CENTER ....
E11 OPERATIONS ....
........ ....
PARENT DEPARTMENT table
KEY

PRIMARY FOREIGN UNIQUE


KEY KEY CONSTRAINT

EMPNO FIRSTNM LASTNM ... DEPT ... TAX_ID


Dependent
000030 SALLY KWAN ... C01 ... 456-78-9101
Table 000090 EILEEN HENDERSON ... E11 ... 101-98-7654
000130 DOLORES QUINTANA ... C01 ... 489-22-8472
000290 JOHN PARKER ... E11 ... 214-32-8045
000300 PHILIP SMITH ... E11 ... 750-18-1912
...... ...... ...... ... ... ... ...
EMPLOYEE table
Referential Integrity (2 of 3)
By definition, a FOREIGN KEY in one table matches
a PARENT KEY
A PARENT KEY value must be UNIQUE, and cannot
be NULL
A FOREIGN KEY value must match a PARENT KEY
or be NULL
DB2 enforcement of referential constraints:
INSERT/UPDATE/LOAD of FOREIGN KEY
Must match PARENT KEY or be NULL
UPDATE of PARENT KEY
Not allowed if any FOREIGN KEYS match original value
Referential Integrity (3 of 3)

DELETEing a row

When DELETEing a parent key, what should be done


to matching foreign keys?
DELETE rows with matching values (CASCADE)
Change matching values to null (SET NULL)
Disallow the DELETE if matching values exist
(RESTRICT / NO ACTION)
Referential Structure

TABLES LINKED BY
REFERENTIAL CONSTRAINTS

RESTAURANTS

.NAME

C N R

DISCOUNT_
RATINGS PALS
TICKETS
.PLACE .FAVOR .NAME
DELETE Rules Exercise

ROWS 1 THROUGH 15 CONTAIN THE FOLLOWING RESTAURANT NAMES:


RESTAURANTS RATINGS PALS DISCOUNT_TICKETS
.NAME .PLACE .FAVOR .NAME

1 ALDO 5 ALDO 10 V&T 15 ALDO


2 V&T 6 V&T 11
3 HORN 7 ALDO 12 V&T
4 4SEAS 8 4SEAS 13 ALDO
9 V&T 14 4SEAS

PARENT C N R

WHAT IS THE EFFECT OF THE REQUEST TO DELETE:


RESTAURANTS RATINGS PALS DISCOUNT TICKETS

ROW 3

ROW 4

ROW 12

ROW 1
SQL DDL

D ATA DEFINITION LANGUAGE


CREATE ALTER DROP

COL1 COL2 COL3 NEW


SQL DML

DATA M ANIPULATION L ANGUAGE


EMPNO SALARY NAME
1137 25000 ANDREW
SELECT 3624 10000 SMITH
8873 13012 JONE
UPDATE 8874 15761 CARTER
9213 45127 FREED
INSERT
9317 17129 ANGELO

DELETE
SQL DCL

DATA CONTROL LANGUAGE


REVOKE

GRANT

CONNECT

COMMIT

ROLLBACK
Locking Strategies

Table Table

Row(s)
OR

Table Space

DB2 employs either strict Table Locking


or
Table Locking in conjunction with Row Locking
for typical Application Processing
Table Lock Modes

IN Intent None

IS Intent Share

IX Intent eXclusive

SIX Share with Intent eXclusive

S Share

U Update

X eXclusive

Z superexclusive

Row Locking also used Strict Table Locking


(See next page)
Row Lock Modes

Minimum* Supporting
Row Lock
Table Lock
S Share IS
U Update IX
X eXclusive IX
W Weak exclusive IX
NS Next key Share IS
NX Next key eXclusive IX
NW Next key Weak exclusive IX

An application does not acquire


Row locks
If it is using Table Locks of
S, U, X, or Z
Table Lock versus Row Locking

Lock T
abl e

T
C
LE
SE
UP
DA
TE
Update WAIT
Lock Mode Compatibility
MODE OF LOCK B
MODE OF
LOCK A IN IS S IX SIX U X Z

IN YES YES YES YES YES YES YES NO

IS YES YES YES YES YES YES NO NO

S YES YES YES NO NO YES NO NO

IX YES YES NO YES NO NO NO NO Table Locks


SIX YES YES NO NO NO NO NO NO

U YES YES YES NO NO NO NO NO

X YES NO NO NO NO NO NO NO

Z NO NO NO NO NO NO NO NO

LOCK MODE OF LOCK B


A
MODE S U X W NS NX NW
S YES YES NO NO YES NO NO
U YES NO NO NO YES NO NO
X NO NO NO NO NO NO NO
Row Locks W NO NO NO NO NO NO YES
NS YES YES NO NO YES YES YES
NX NO NO NO NO YES NO NO
NW NO NO NO YES YES NO NO
Some Scenarios

BR
GARAGE

BATH

B'FAST
FAMILY MASTER
BR

KITCHEN
BATH

LIVING
BATH STOPLETT
DINING
CONSTRUCTION
CLOSET BR
Unit of Recovery

SAVINGS CHECKING

POINT OF BANK NEW POINT OF


CONSISTENCY TRANSFER CONSISTENCY

OLD DATA UPDATES UPDATED

DATA UNIT OF RECOVERY DATA


COMMIT

POINT OF NEW POINT OF


CONSISTENCY TERMINATION CONSISTENCY

OLD DATA UPDATES BACK OUT UPDATES OLD

DATA DATA

ABORT END ABORT

RECOVERY IS TO LAST POINT OF CONSISTENCY


Commit and Rollback

Operates on a Unit of Recovery

COMMIT
Changes will be made
Row Locks released
Certain Table Locks released

ROLLBACK
Changes backed out
All Locks released
Commit versus Rollback

COMMIT ROLLBACK

OS/2 or Normal prog. term. Prog. abend


UNIX EXEC SQL COMMIT EXEC SQL ROLLBACK

Windows EXEC SQL COMMIT Program termination


(normal or abend)
EXEC SQL ROLLBACK

CICS Normal trans. term. Trans. abend


SYNC POINT cmd. SYNCPOINT ROLLBACK
cmd
ABEND cmd
Data Recovery (1 of 2)

Backup
Updated
Database
Database
(failure)
"COMMIT"

"UPDATE" "UPDATE"

LOG
Data Recovery (2 of 2)
UTILITY
Backup

Recovered
Restore Database

"UPDATE"

LOG
CLP Syntax

db2

option-flag db2-command
sql-statement
?
phrase

message

sql-state

class-code
Starting a CLP Session

non-interactive mode

db2 connect to eddb


db2 "select * from syscat.tables" more |

(double quotes may be required)

interactive mode

db2
db2=> connect to eddb
db2=> select * from syscat.tables
Command Center
QUIT versus
TERMINATE versus CONNECT RESET

CLP Terminate CLP Disconnect


COMMAND Back-end Process database Connection

quit No No

terminate Yes Yes


Yes if
connect reset No CONNECT=1
(RUOW)
Unit Summary
Since completing this unit, you should be able to:
Identify DB2 family products
Explain DB2 workstation component functions
Identify DB2 objects
Discuss the concepts of relational tables and DB2's
implementation of referential integrity
Define a unit of recovery and detail the basic locking
strategies used by DB2
Identify the key differences between static SQL and
other application alternatives for accessing DB2 data
Identify DB2's role in X/OPEN

You might also like