Documente Academic
Documente Profesional
Documente Cultură
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
15 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
30 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
2.2.1. Relational DBMS...................................................................................4
10 2.2.2. HIERARCHICAL DBMS........................................................................6
2.2.3. Net Work DBMS....................................................................................7
2.3. SAMPLE DB2 DATABASE..................................................................................8
3. STRUCTURE OF DB2.........................................................................................9
3.1. HIERARCHY OF DATA STRUCTURES.................................................................9
15 3.2. DATABASES.....................................................................................................9
3.3. DB2 STORAGE GROUPS..................................................................................9
3.4. TABLE SPACES................................................................................................9
3.4.1. Simple Tablespace................................................................................9
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
6285 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
6300 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
3.4.2. Segmented Table Space.......................................................................9
20 3.4.3. Partitioned Table Space........................................................................9
3.5. TABLES...........................................................................................................9
3.6. INDEX SPACES................................................................................................9
3.7. INDEXES..........................................................................................................9
3.8. VIEWS.............................................................................................................9
25 3.9. SYNONYMS.....................................................................................................9
3.10. ALIASES........................................................................................................9
3.11. DB2 CATALOG...............................................................................................9
3.12. DB2 DIRECTORY...........................................................................................9
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
12555 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
12570 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
3.13. ACTIVE AND ARCHIVE LOGS...........................................................................9
30 3.14. BUFFER POOLS.............................................................................................9
4. DATA TYPES.....................................................................................................39
4.1. NUMERIC DATA..............................................................................................39
4.1.1. Nulls.....................................................................................................39
4.2. STRING DATA................................................................................................39
35 4.3. CHARACTER FORMAT....................................................................................39
4.4. DATE/TIME DATA...........................................................................................39
4.5. EQUIVALENT COBOL DECLARATIONS OF DATA TYPES.....................................39
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
18825 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
18840 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
5. SQL PROGRAMMING.......................................................................................49
5.1. DDL STATEMENTS.........................................................................................51
40 5.1.1. Create Database.................................................................................51
5.1.2. Create Table Space.............................................................................51
5.1.3. Create Table........................................................................................51
5.1.4. Create View.........................................................................................51
5.1.5. Create Index........................................................................................51
45 5.1.6. Alter Table............................................................................................51
5.1.7. Drop.....................................................................................................51
5.2. DML STATEMENTS........................................................................................64
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
25095 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
25110 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
5.2.1. Select...................................................................................................64
5.2.2. Joining Tables......................................................................................64
50 5.2.3. Sub Queries.........................................................................................64
5.2.4. Union...................................................................................................64
5.2.5. Insert....................................................................................................64
5.2.6. Update.................................................................................................64
5.2.7. Delete..................................................................................................64
55 5.3. CONTROL STATEMENTS.................................................................................82
5.3.1. Grant....................................................................................................82
5.3.2. Revoke.................................................................................................82
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
31365 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
31380 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
5.3.3. Commit................................................................................................82
5.3.4. Roll Back..............................................................................................82
60 6. PROGRAM STRUCTURE.................................................................................87
6.1. HOST VARIABLES..........................................................................................87
6.1.1. Declaring Host Variables.....................................................................87
6.2. INDICATOR VARIABLES...................................................................................87
6.3. SQLCA.......................................................................................................87
65 6.4. COBOL STRUCTURE OF SQLCA...................................................................87
6.5. SQLCA RETURN CODES...............................................................................87
6.6. SQLCA WARNINGS.......................................................................................87
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
37635 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
37650 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
6.7. IMPORTANT SQL CODES................................................................................87
6.8. STATIC SQL..................................................................................................87
70 6.9. DYNAMIC SQL..............................................................................................87
6.10. EXAMPLE FOR A DB2 APPLICATION PROGRAM.............................................87
7. PROGRAM PREPARATION............................................................................125
7.1. STEPS IN PROGRAM PREPARATION..............................................................125
7.2. DCLGEN (DECLARATIONS GENERATOR )......................................................125
75 7.3. PRECOMPILE...............................................................................................125
7.4. BIND...........................................................................................................125
7.4.1. Binding A DBRM To A Package.........................................................125
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
43905 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
43920 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
7.4.2. Binding An Application Plan..............................................................125
7.5. COMPILE AND LINKEDIT...............................................................................125
80 7.6. OVERVIEW OF DB2 APPLICATION PROGRAM PREPARATION AND EXECUTION 125
7.7. ASSOCIATING LOAD MODULES AND PACKAGES............................................125
8. SECURITY FEATURES...................................................................................143
8.1. PRIVILEGES.................................................................................................143
8.2. REFERENTIAL INTEGRITY.............................................................................143
85 8.2.1. DB2 Enforcement Of Referential Integrity.........................................143
8.2.2. Referential Integrity Enforcement Rules...........................................143
8.2.3. Example For Referential Integrity Violation.......................................143
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
50175 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
50190 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
8.3. DATABASE RECOVERY IN CASE OF FAILURE................................................143
8.3.1. Unit Of Recovery...............................................................................143
90 8.3.2. Data Recovery...................................................................................143
9. CONCURRENCY.............................................................................................160
9.1. CONCURRENCY...........................................................................................160
9.2. LOCKING STRATEGY....................................................................................160
9.3. LOCK SIZES AND TYPES..............................................................................160
95 9.4. ACQUIRE RELEASE PARAMETERS................................................................160
9.5. ISOLATION PARAMETER...............................................................................160
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
56445 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
56460 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
10. DB2I (DB2 INTERACTIVE )...........................................................................170
10.1. DB2I.......................................................................................................170
10.2. SPUFI.................................................................................................... 170
100 11. UTILITIES.......................................................................................................174
11.1. LOAD........................................................................................................174
11.2. RUNSTATS.................................................................................................174
11.3. REORG......................................................................................................174
12. ADVANCED DB2...........................................................................................182
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
62715 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
62730 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
105 12.1. MORE ABOUT INDEXES..............................................................................182
12.1.1. Example Of An Index.......................................................................182
12.1.2. Clustered Indexes............................................................................182
12.1.3. Non Clustered Indexes....................................................................182
12.2. SPECIAL REGISTERS.................................................................................182
110 12.3. MORE ABOUT LOCKS.................................................................................182
12.3.1. Modes Of Table And Tablespace Locks..........................................182
12.3.2. Modes Of Row And Page Locking..................................................182
12.3.3. Lock Mode Compatibility Of Table And Table Space Locks............182
12.3.4. Lockmode Compatibility Of Row And Page Locks..........................182
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
68985 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
69000 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12
115 12.4. INVOKING ONLINE UTILITIES.......................................................................182
The Purpose of this document is to train fresh Software Engineers who would like
to get familiarized with DB2 and as a reference material for application
programmers.
75255 3. Introduction
INDEX X1
DATABASE
DB2 (IBM DATABASE2) is a highly successful relational database management
system. DB2 enables it’s users to create, update and control relational database
INDEX X2
using STRUCTURED QUERY LANGUAGE (SQL). Designed to meet the needs
APPLICATION
of small and large business PROGRAM
alike, DB2 is available on a number of platforms. we
will be dealing with DB2 on MVS. STORAGE
GROUP G1
INDEX 2
PARTITIONED INDEX X3
RESULT
CALL STORAGE
75270 DB2 FORPART 1 DB2 FOR DB2 FOR
* SELECT SELECT GROUP G2
HP-UX SOLARIS WINDOWS /NT
VOLUME 1 INDEX VOLUME
PARTITIONED 2
X3 TABLESPACE 2
VOLUME2
PARTDB2
2 FOR (3380)
SINIX MAIN MEMORY
DATA TABLE
TABLE
TABLE12