Beruflich Dokumente
Kultur Dokumente
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
S/390, S/370
Communication Support DB2 DB2 Relational Connect (EE or EEE) DRDA Application Server Oracle Database DB2 Connect
Workgroup Edition
ODBC support
Enterprise Edition
Administration Client
JDBC support
EnterpriseExtended Edition
Accessing DB2
Command Line Processor
Commands Interactive SQL
Administration Tools
Control Center Command Center Alert Center Script Center Event Analyzer Journal Tools Settings
Applications
APIs Embedded SQL Call Level Interface JAVA
End-User Access
END USER Application Analyst
Application Programmer
(I/C Consultant)
Query Tool
DBA
Systems Programmer
DATA BASE
What's in an Instance?
DB2 Product
INSTANCE_1
CATALOG
INSTANCE_2
DB CONFIG FILE_1
JOIN (federated)
CATALOG
DB_1
LOG
DB_3
LOG
DB CONFIG FILE_3
CATALOG
DB_2
LOG
DB CONFIG FILE_2
CATALOG
DB_4
LOG
DB CONFIG FILE_4
Connect to Database
Application Requestor
Application Server
database
Catalog
Database 2
Table1 Index1
Table2
Table3
Table2 View1
Index1 Index2
VIEW
BASE TABLE
AS IT EXISTS ON STORAGE
VIEW
AS THE PROGRAM's LOGIC SEES IT
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
Table/Column Descriptions
PREPARE
Package:
Static SQL
Vacation Travel Booking Vacation Code: Origination: Travel Date:
Exp. Date:
Dynamic SQL
Vacation Travel Unlimited Type: Destination: Country: Language: Activities: Cooking, Laundry, Household: Number Traveling: Mode of Transportation: Cost: Date: State:
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 .
SQLPrepare(...);
versus
Dynamic
EXEC SQL PREPARE ... EXEC SQL EXECUTE ...
...
SQLExecute(...);
SQLFetch(...);
SQL statements EXEC SQL FETCH ... prepared during application execution
..
...
Prepare
Prepare
Execute
Execute
DB2
DB2 client
parameters
DB2 client
OLEDB
Virtual Table
Java Applications
SQLJ Application
JDBC
DB2 Client
JDBC Client
TCP/IP Socket
Stored Procedures
Client Application Run-Time Client
DB2 Server
DB2 Database
Network
Client Application Run-Time Client Stored Procedure
DB2 Server
DB2 Database
DB2 Server
(3)
Referential Integrity
Some Basic Terms
PRIMARY KEY
Parent Table
DEPARTMENT table
FOREIGN KEY UNIQUE CONSTRAINT
TAX_ID 456-78-9101 101-98-7654 489-22-8472 214-32-8045 750-18-1912 ...
Dependent Table
EMPLOYEE table
Referential Structure
TABLES LINKED BY REFERENTIAL CONSTRAINTS
RESTAURANTS .NAME
RATINGS .PLACE
PALS .FAVOR
PARENT
ROW ROW
3 4
ROW 12 ROW 1
SQL DDL
SQL DML
SQL DCL
Locking Strategies
Table Table
OR
Row(s)
Table Space DB2 employs either strict Table Locking or Table Locking in conjunction with Row Locking for typical Application Processing
Lock T able
SE LE C T
Update
UP DA TE
WAIT
Table Locks
LOCK A MODE S U
MODE OF LOCK B S YES YES NO NO YES NO NO U YES NO NO NO YES NO NO X NO NO NO NO NO NO NO 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
Row Locks
X W NS NX NW
Some Scenarios
BR BATH B'FAST
GARAGE
FAMILY
MASTER BR
BATH BATH BR
STOPLETT CONSTRUCTION
CLOSET
Isolation Levels
ID NAME QTY
DISP
10
KEYB
MOUSE
15
CABLE
18
F E T C H
NO ROW LOCKS
3
FOR READ-ONLY
4
CURSORS
5
CPU
1
6
SOUND
COMMIT POINT
Application Bound
RS or RR
CS
UR
Unit of Recovery
SAVINGS POINT OF CONSISTENCY OLD DATA CHECKING NEW POINT OF CONSISTENCY UPDATED DATA COMMIT
TERMINATION
DATA UPDATES
ABORT
END ABORT
ROLLBACK
Prog. abend EXEC SQL ROLLBACK Program termination (normal or abend) EXEC SQL ROLLBACK Trans. abend SYNCPOINT ROLLBACK cmd ABEND cmd
CICS
Data Recovery
Database
LOG
Restore
Recovered Database
"UPDATE"
LOG
CLP Syntax
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
No Yes No
No Yes
Yes if CONNECT=1 (RUOW)
terminate
connect reset
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