Академический Документы
Профессиональный Документы
Культура Документы
DB2
Table of Contents
INTRODUCTION TO DB2...........................................................................................................................5
1.1 Data Base Management System.............................................................................................................5
1.1.1) Relational Data Base Management System...................................................................................5
1.2) D B 2.....................................................................................................................................................5
1.2.1) Structured Query Language (SQL)................................................................................................5
1.3) How does a COBOL program use DB2 services..................................................................................6
1.3.1) Host Variables................................................................................................................................6
1.3.2) SQL Communication Area.............................................................................................................6
1.3.3) SQL statements..............................................................................................................................6
1.4) Handling a request.................................................................................................................................6
SYSTEM STRUCTURE................................................................................................................................8
2.1) Major Components................................................................................................................................8
2.1.1) System Services.............................................................................................................................8
2.1.2) Locking Services............................................................................................................................8
2.1.3) Database Services...........................................................................................................................8
2.1.3.1 ) Precompiler............................................................................................................................9
2.1.3.2) Bind.........................................................................................................................................9
2.1.3.3) Runtime Supervisor.................................................................................................................9
2.1.3.4) Data Manager..........................................................................................................................9
2.1.3.5) Buffer Manager.......................................................................................................................9
2.1.4) Distributed Data Facility................................................................................................................9
2.2) Detailed Control Flow.........................................................................................................................10
2.2.1) Syntax Checking..........................................................................................................................11
2.2.2 ) Optimization................................................................................................................................11
2.2.3) Package Generation......................................................................................................................11
2.2.4.) Authorization checking...............................................................................................................11
2.3) Packages Plans and Collections..........................................................................................................12
DATA TYPES AND OPERATORS...........................................................................................................13
3.1) Data Types..........................................................................................................................................13
3.1.1)Numeric data.................................................................................................................................13
3.1.2) String Data...................................................................................................................................13
3.1.3) Date/Time.....................................................................................................................................13
3.2) Operators and Expressions..................................................................................................................14
3.3) Scalar Functions..................................................................................................................................14
DB2 DATA STRUCTURES........................................................................................................................16
4.1) Introduction.........................................................................................................................................16
4.2) Database..............................................................................................................................................16
4.3 ) Table Spaces.......................................................................................................................................16
4.3.1 ) Simple Table Space.....................................................................................................................16
4.3.2) Partitioned Table Space................................................................................................................17
4.3.3) Segmented Table Space...............................................................................................................17
4.4) DB2 Stored Tables..............................................................................................................................17
4.5) Index....................................................................................................................................................18
4.6) Index Spaces........................................................................................................................................19
4.7) Storage Groups....................................................................................................................................19
4.8) Views...................................................................................................................................................19
4.9) Alias....................................................................................................................................................20
4.10) The hierarchy of DB2 objects...........................................................................................................20
INTEGRITY.................................................................................................................................................21
5.1) Introduction.........................................................................................................................................21
5.2) Primary key.........................................................................................................................................21
5.2.1) Definition.....................................................................................................................................21
5.3) Entity Integrity....................................................................................................................................22
11.1 ) Introduction......................................................................................................................................41
11.3 ) GRANT AND REVOKE.................................................................................................................41
11.4 ) The GRANT OPTION.....................................................................................................................41
EMBEDDED SQL........................................................................................................................................42
12.1 ) Introduction......................................................................................................................................42
12.2 ) Preliminaries....................................................................................................................................42
12.3 ) Operations Involving CURSORS....................................................................................................43
12.3.1 )DECLARE.................................................................................................................................44
12.3.2 )OPEN.........................................................................................................................................44
12.3.3)FECTCH.....................................................................................................................................44
12.3.4)CLOSE........................................................................................................................................44
12.3.5)WITH HOLD clause...................................................................................................................45
TRANSACTION PROCESSING................................................................................................................46
13.1) Introduction.......................................................................................................................................46
13.2) COMMIT and ROLLBACK.............................................................................................................46
13.3) Three CONCURRENCY PROBLEMS............................................................................................47
13.3.1)The LOST UPDATE problem....................................................................................................47
13.3.2)The UNCOMMITED DEPENDENCY problem........................................................................47
13.3.3)The INCONSISTANT ANALYSIS problem.............................................................................48
13.4) Solution.............................................................................................................................................48
13.5) Locking Facilities..............................................................................................................................49
13.5.1) LOCK TABLE...........................................................................................................................49
13.5.2) The ISOLATION parameter......................................................................................................49
13.5.2.1)CURSOR STABILITY........................................................................................................49
13.5.2.2) REPETABLE READ..........................................................................................................49
13.5.3)LOCK SIZE................................................................................................................................50
13.5.4) The ACQUIRE/RELEASE parameters......................................................................................50
13.6) DEADLOCK.....................................................................................................................................50
DYANAMIC SQL........................................................................................................................................51
14.1)Introduction........................................................................................................................................51
14.2) PREPARE/EXECUTE......................................................................................................................51
14.3) EXECUTE IMMEDIATE.................................................................................................................52
ADMINISTRATION FACILITIES............................................................................................................53
15.1) Introduction.......................................................................................................................................53
15.2) DB2 INTERACTIVE INTERFACE.................................................................................................53
15.2.1) SPUFI.........................................................................................................................................54
15.2.2) DCLGEN....................................................................................................................................54
15.2.3)Program Preparation....................................................................................................................54
15.2.4)Precompile...................................................................................................................................54
15.2.5) Bind / Rebind / Free...................................................................................................................54
15.2.5) RUN...........................................................................................................................................55
15.2.6) DB2 Commands.........................................................................................................................55
15.2.7)Utilities........................................................................................................................................55
15.2.8)Catalog Visibility........................................................................................................................55
15.2.9) DB2I Defaults............................................................................................................................55
15.2.10) EXIT.........................................................................................................................................55
15.3) EXPLAIN..........................................................................................................................................55
15.4) Database utilities...............................................................................................................................56
INTRODUCTION TO DB2
A Data Base, which consists of some collection of persistent data that is used by the application
systems of some given enterprise. These are designed and managed to store large quantities of information.
A Data Base Management System (DBMS) is a software package that manages the data stored in
databases. Data base approach will help to maintain data independence, avoid redundancy, inconsistency
and also provide better security. Thus DBMS provide an environment that is both convenient and efficient
to use in retrieving and storing data base information.
A Relational Data Base System presents all information in form of tables. Tables consist of rows
and columns. This concept is in close correspondence with mathematical concept of relations and hence the
name.
1.2) D B 2
This is the language by which request to DB2 are made.DB2 supports SQL, which provides
facilities for application programming as well as for data base management. SQL is both ANSI and ISO
standard. In fact it is the language used to access all relational databases.
The statements, which make up SQL are commonly categorized in to Data Definition Language
(DDL), Data Manipulation Language (DML), and Control statements. DBA uses DDL for defining various
objects. Application programmers uses DML to work with DB2. Control statements are used to handle
authorization to various resources.
When DB2 is used through COBOL, SQL statements are to be included in the program. Following
are the three things that are to be included when using DB2 in COBOL programs Host variables, SQL
communication Area, and SQL statements.
These are used for retrieving and putting data into DB2 tables. Host variables have to be defined
in the program, which is used to receive the data DB2 returns and from which DB2 can get the data to
update tables. They are called host variables because they reside in the storage owned by host program.
DB2 provides the feedback about the success of each operation by Storing information in SQLCA.
So in COBOL program SQLCA have to be included.
SQL statements actually does the data base work required by the program. SQL
statements can be embedded into a programming language. These SQL statements are not understood by C,
COBOL etc. So before compiling the program, a preliminary process (Precompiler) must pull out the SQL
statements.
1.4) Handling a request
When a request to update the database comes to DB2 from the user. The application manager
passes the userid to DB2. DB2 will check for the authorization of the user. It maintains a catalog to see
whether the user is authorized. If not authorized DB2 will return a code indicating it has refused the request
due to unauthorized user id. There are multiple concurrent processing handled by DB2. To avoid a possible
confusion DB2 puts a lock on data. DB2 maintains a log which keeps record about everything that is done
to the data. DB2 always writes to the log before writing to the data after the successful updation it will
mark a COMMIT to the log. Since the update is completed DB2 releases the lock and the operation
completed successfully
SYSTEM STRUCTURE
2.1) Major Components
There are four major components, each of which divides into a number of subcomponents. They
are
The system service component
The locking services
The database services
The distributed data facility component
The system services supports the system operations. This handles DB2 system related tasks
including controlling connections to other MVS subsystems, handling system startup, shutdown and
operator communications, managing system log, gathering system-wide statistics, performance auditing
and accounting informations etc.
The system logs are data sets used to record the information for recovering the user and system
data in the event of system failure. The logs are of two types; active log and archive log.
Locking services are provided by an IMS Resource Lock Manager (IRLM), which is a general-
purpose locking manager. This is used to control the concurrent access to DB2 data.
This is used to retrieval and updation of database i.e. implements the functions of SQL. This
includes five subcomponents. They are:
Precomipler
Bind
Runtime Supervisor
Data Manager
Buffer Manager
2.1.3.1 ) Precompiler
This is a preprocessor for host programming languages. Precompiler analyses the host language
source module, stripping out the SQL statements and replace them by host language CALL statements. The
precompiler produces two output files. The first is intermediate source program, Which contains the
COBOL statements. The original SQL statements in the program will be commented out so that COBOL
compiler ignores them. Second file produced by precompiler called Data Base Request Module (DBRM).
2.1.3.2) Bind
This is used to bind a DBRM to produce a package and also it binds together a list of packages to
produce an application plan. The package can be thought as a set of internal control structures, representing
the compiled form of original SQL statements in the DBRM.
Collections are a set of logically related packages, which does not have a physical existence. All
the packages used in a given application are assigned to the same collection. Host language compiler,
which compiles the modified source code to produce the Object module for the host language.
This is resident in the main storage during the execution and it overseas the execution of job.
When the SQL statements are executed, control first goes to runtime supervisor, which uses the control
informations in the plan to request appropriate operations on the part of Data manager.
This is a very sophisticated access method. It performs the normal access method functions like
search, retrieval etc. It also invokes the other system components to invoke locking ,I/O operations etc.
This is a component responsible for transferring data between external storage and memory. It
uses several methods to optimize its performance so that amount of I/O can be reduced.
This section will explain how to prepare and execute DB2 embedded application program. After preparing
the program with embedded DB2 statements it has to be precompiled first. This is because the host
language compiler does not understand the embedded DB2 statements. The precompiler replaces all SQL
statements with CALL statements. The SQL statements will be commented out. Precompiler uses SQL
statements to build a DBRM, which is stored in a partitioned dataset. DBRM contains edited form of SQL
statements together with some additional informations. So the output of precompilation is modified source
code and DBRM.
Modified source code is compiled and linkedited in normal way by using the host language compiler.
Bind is really an optimizing compiler. It will convert SQL statements into optimized internal form. Its input
is DBRM and output is a package. The major functions performed by bind are
Syntax checking
Optimization
Package generation
Authorization checking
2.2.2 ) Optimization
Bind includes an optimizer to choose for each SQL statement an optimal access strategy for
implementing that statement. For example when the user wants to access some data the access path is
selected by the optimizer. Bind will generate a code that is tightly bound to optimizer’s choice of path.
Bind checks for authorization. It check for whether the user is allowed to perform the operations
requested on DBRM and also whether allowed to assign packages applicable to packages collection.
Bind also performs the plan bind. The input of this process is a list of packages. Output is an
application plan, which is stored in DB2 directory. This also done some authorization checking such as
whether the owner is authorized to execute all application packages.
At the time of execution both load module (from modified source code) and application plan (from
DBRM) to be used. The load module is loaded to memory and it stars execution. When it reaches the first
call to DB2 language interface module it passes the control to runtime supervisor. The runtime supervisor
retrieves the application plan from DB2 directory and loads it into memory. Then the control is passed to
Data manager, which performs the necessary operations on the data and passes the result back to the
program.
Package is a compiled form of DBRM. Plan is a list of packages. Plan may consist of more than
one packages. So if a given DBRM has to be recompiled, the appropriate package has to be bind not the
entire plan. If multiple plans involve the same DBRM, that can be compiled once and the corresponding
package can be referenced multiple times instead of binding the DBRM each time.
Collections is a logical grouping of packages. It is even possible to add a new package to a plan
without binding it. This is by using the concept of collections. When a plan is bound the input can be a
collections. This is equivalent to adding all packages in that collection. Including packages in the collection
can be done after plan is bound. Whatever packages in the collection while plan is executed is considered to
be a part of the plan.
3.1.1)Numeric data
3.1.3) Date/Time
DATE Eight unsigned packed decimal occupying 4 bytes
YYYYMMDD
TIME 6 unsigned packed decimal occupying 3 bytes
HHMMSS
TIMESTAMP Sequence of 20 unsigned packed decimal digits
YYYYMMDDHHMMSSNNNNNN
DB2 provide a number of scalar operators that can be used in making scalar expressions.
A scalar expression consists of scalar operands to produce another scalar value. These can appear
in SQL statements with SELECT, HAVING, WHERE etc. There are six types of scalar expressions. They
are Numeric, Character, Graphic, date, time,and timestamp.
E.g. Numeric Expression
STATUS
WEIGHT = WEIGHT*23
E.g. Character string
PNAME
INITIALS || LASTNAME
Scalar functions applied to a single column or expressions and operate on single value. The result
will be transformed version of column or expression. These can be executed in the
SELECT,WHERE,HAVING etc.
In MVS environment, the relational database manager itself is considered as a subsystem. For
each subsystem there are some system objects. DB2 data structures are treated to as DB2 objects. Each
DB2 object is used to support the structure of the data being stored. This section will detail about various
DB2 objects.
4.2) Database
A database is a collection of logically related objects such as tables together with their associated
index and the spaces which contain these tables, and index. It thus consists of a set of tablespaces together
with a set of index spaces. For a stored tables all its associated index must be wholly contained in a single
database.
Objects are grouped together in a database for operational reasons. Operator can make the
database available or unavailable for processing. Database is logical and the data can be contained in single
disk or a set of disk.
A table space can be thought as a logical (Not in physically adjacent areas) address space use to
hold tables. It is at the tablespace level that storage is actually allocated. The maximum size of tablespace is
64GB and it is divided into pages, which are written to or read from a DASD at the time of an operation.
There is no limit for number of tablespace in a database or number of databases. Table Space can be
divided into three types
Simple
Partitioned
Segmented
A simple table space can contain one or more stored tables but one is the best option. Since more
than one logically related tables are present, records for different tables can be clustered together to
improve the access times. But in the case of sequential search the system will be slowed down as it has to
search not only the stored records of the required table but also of the other tables that happen to be mixed
up with first one. So one table per table space is the most satisfactory arrangement for simple table space.
This is used to store very big tables with large number of rows. In such tables it is operationally
difficult to handle the entire table as one unit. A partitioned table space contains one stored table,
partitioned. Individual partitions are independent so that they can be recovered independent of each other.
This also contains more than one stored tables. But here it will not support cross table clustering
i.e. do not allow the records of different tables to be interleaved on a single page as in simple table space.
Table space is divided in to segments. No segment is allowed to contain records from more than one table.
Sequential access to a particular table is more efficient. This can handle variable length records. So these
are more efficient as compared to simple table space.
This is a stored representation of a base table. It consists of a set of stored records, one for each
data row in the base table. A stored record is not identical to corresponding row of base table. It consist of a
byte string which include
A stored record prefix containing control information
Up to N storage fields where ‘N’ is the number of columns of base table
A length prefix for the field which are of variable length
A null indicator prefix indicating nulls
An encoded value of the actual data
There is no gap between the fields. The varying fields contain only the actual value. All internally stored
records are addressed by RID or Record ID. RIDs are unique within the containing table space. From the
figure shown RID contain two parts: The page number and the byte offset from the bottom of the page to
identify the required slot.
4.5) Index
An index can be defined as a DB2 tool used to locate the row that contains a given value. When a
specific row is required DB2 reads the index finds the pointer to that row and then read the page contains
the row. So Indexing provides uniform and predictable performance for retrieval operations.
Index consist of three levels: a root page, intermediate pages, leaf pages. The leaf level contains an
entry for each distinct value for the indexed field. Intermediate level contains an entry for each leaf page.
Thus root page, intermediate page, leaf page provides a direct and fast access to indexed data. A stored
table can have any number of associated index and hence any number of logical ordering on it.
An index space is used to store an index. The correspondence between index and index space is
always one to one. An index space is created automatically when an index is created. Index spaces can be
recognized and recovered independently.
A storage group is a named collection of DASD volumes. Each table space and an index space
normally have a storage group associated with it. Within each storage group data is stored by using VSAM
Linear Data Set (LDS).
4.8) Views
This is a virtual table that consisting of SQL SELECT statements to access data from one or more
tables. A view never stores the data. When user wants to access the view, SQL statement that defines the
view will be executed and the user gets the result. So these can be called as a users table whereas the data
reside in the actual tables on which the view is based. This provides a simplified coding and more security
as the data, which are not required, will be omitted from the view.
4.9) Alias
A locally defined name for table or a view, in the same local DB2 system or in a remote DB2
system. Alias gives DB2 location independence because an alias can be created for a table at a remote site,
thereby freeing the user from specifying the site that contains the data. Alias can be used as a global one
because it can be used by anyone.
INTEGRITY
5.1) Introduction
The term integrity is used in database contexts to refer to accuracy, validity or correctness of data
in the database. This is very important and is handled by system than by user. Integrity constraints to be
specified during database definition. This will be stored in catalog and will be used by the system during
various operations. DB2 includes two general integrity rules. These are brought into picture using two keys
called primary key and foreign key.
Primary key is a unique identifier for the table. Even that can be composite i.e. more columns can
be combined together to form a unique key. But in a table there can be more than one unique identifier. In
that case table has multiple candidate keys out of which only one will be the primary key and the others
called alternate keys. Primary keys are very important as it provide the basic row level addressing
mechanism. Thus by using the primary key system can pinpoint some specific rows in a required table.
5.2.1) Definition
Primary key can be defined when the base table created through CREATE TABLE or can be
added to an existing table through ALTER TABLE. Every column participating in primary key must be
explicitly declared as NOT NULL. After creating the primary key appropriate unique index has to be
defined. This index called primary index enforces the uniqueness of primary key.
To an existing table primary key can be added using ALTER TABLE command. A suitable
unique index must already exist for ALTER TABLE to succeed, and also the column for primary key
should be declared as NOT NULL.
E.g. CREATE TABLE NTP
(EMPNO CHAR(5) NOT NULL,
EMPNAME CHAR(20) ,
PRIMARY KEY (EMPNO));
CREATE UNIQUE INDEX IND1 ON NTP(EMPNO);
It is also possible to remove the primary key from an existing table.
E.g. ALTER TABLE NTP DROP PRIMARY KEY;
Entity integrity rule specifies that Primary key should be unique and it should not accept a NULL
value. This is because these values serve to identify the entire row. In the case of composite primary key
each individual value of the primary key should be wholly non null.
A foreign key is a column in one table that matches values to the primary key in another table. The
foreign key can also be null. Each value of the foreign key must match with a corresponding value of
primary key. The table, which contains the foreign key, is called referencing table and the table which
contain the corresponding primary key is called referenced or target table.
5.4.1) Definition
The foreign key can be defined when the base table is created using CREATE TABLE. It can also
be added to or deleted from an existing table using ALTER TABLE. It is not necessary to create an index
on foreign key.
E.g. CREATE TABLE EMP
(EMP# CHAR(5) NOT NULL,
EMPNAME CHAR(20) ,
PRIMARY KEY (EMP#)
FOREIGN KEY FK1 (EMPNO) REFERENCES NTP);
ALTER TABLE EMP DROP FOREIGN KEY FK1;
Referential constraint limits a set of foreign key values to a set of primary key values. So
referential integrity enforces referential constraints. So the database must not contain an unmatched foreign
key value.
When a row contains the primary key is deleted necessary changes to be occurred for the matching
foreign keys. There are three options for this: CASCADE, SET NULL, RESTRICT
CASCADE when the target row is deleted from target table the row which contain the foreign key of
referencing table also get deleted.
SETNULL When the target row is deleted the foreign key will be set to null.
RESTRICT The delete is restricted.
This rule to be specified when defining the foreign key. Default is RESTRICT.
E.g. CREATE TABLE EMP
(EMP# CHAR(5) NOT NULL,
EMPNAME CHAR(20) ,
PRIMARY KEY (EMP#)
FOREIGN KEY FK1 (EMPNO) REFERENCES NTP ON DELETE CASCADE);
SQL is used by DB2 for operating on database. In this programmer has to specify what data he
want to retrieve and not how to do it. In SQL a single request can be formulated in a number of different
but functionally equivalent ways. For example a nested query can always be converted to an equivalent
join. SQL is a nonprocedural language. An SQL manipulation statement can operate on a table and the
result can be obtained on another table. One retrieval statement can retrieve multiple rows or one update
can update can change multiple rows. This feature is called relational closure, which makes relational
database much easier.
SQL can be categorized based on functionality. On the basis of this, it is divided into three
The Data Control Language(DCL) provide the control statements that govern data security
The Data Definition Language(DDL) for creating and maintaining the data structure
The Data Manipulation Language(DML) for accessing and modifying the data
Another way to classify SQL is by execution type. There are two types
The production where the SQL is planned and executed. Here all the requirements are well known
The ad-hoc where its undefined until an immediate need is identified
7.1) Introduction
Data definition statements can be divided into two broad classes: Logical and Physical. The end
user will be normal using the logical statements. The DDL statements are CREATE, ALTER, DROP. The
following table summarizes these operations on various DB2 objects
DB2 Objects CREATE ALTER DROP
Storage Group Y Y Y
Database Y N Y
Tablespace Y Y Y
Table Y Y Y
Index Y Y Y
View Y N Y
In this section logical statements are covered in detail. The principal logical DDL statements are
CREATE TABLE, ALTER TABLE, DROPTABLE,CREATE VIEW, DROP VIEW, CREATE
INDEX,DROP INDEX.
This creates the base table. A base table consists of rows and columns to define physical
characteristics of data to be stored. The format is
CREATE TABLE <table name>
(column definition [, column definition]...
[, Primary key definition]
[,alternate key definition]
[,foreign-key definition ])
[,other parameters];
The table name which is user defined gives a unique identity to the table. The column definition can take
the form column data-type [NOT NULL/NOT NULL WITH DEFAULT/UNIQUE]
The square brackets are used to show that they are optional. System will take the default values where
applicable.
A new table can be created with the same shape as some existing table using the option LIKE. But
the new table created will not inherit Primary key, Alternate key, Foreign key definitions.
E.g. CREATE TABLE SCOPY LIKE S;
This is same as CREATE TABLE SCOPY
( S# CHAR(5) NOT NULL,
SNAME CHAR(20) NOTNULL WITH DEFAULT,
STATUS SMALLINT NOT NULL WITH DEFAULT,
CITY CHAR(15));
An existing table can be altered by using ALTER TABLE. For example a new column can be
added to an existing table.
E.g. ALTER TABLE NTP ADD EMPLEVEL SMALLINT;
This statement adds a column to the extreme right in the table NTP. This should not be declared as
NOTNULL. But ALTER cannot change the width or data type of an existing column.
7.4 ) DROP TABLE
An existing table can be deleted using this option. The specified table is deleted from the system.
All indexes, views etc defined on this table will be dropped.
E.g. DROP TABLE NTP;
7.6 ) INDEXES
Indexes can be created and dropped using DDL statements. Any number of indexes can be created
on a base table. The two DDL statements are CREATE INDEX and DROP INDEX.
This is used to delete an index and the corresponding entry will be deleted from the catalog.
E.g. DROP INDEX IND1;
8.1 ) Introduction
There are four SQL statements for manipulating the data that has been loaded into the tables. They
are SELECT,INSERT,UPDATE,and DELETE. SELECT retrieves the data,UPDATE changes the existing
values, DELETE removes rows from the table, INSERT adds new rows into the table. This section gives a
detailed description of all the four DML statements.
8.2 ) SELECT
SELECT is used to retrieve the data from the base table. The format is
SELECT [ALL/DISTINCT] <column names>
FROM <table name>
[WHERE <conditional expression>]
[GROUP BY <column names> ]
[HAVING <conditional expression>]
[ORDER BY <column names>];
The result of the above query will be another table derived from the base table.
Resultant table obtained as a result of a query can be in an ordered form. For this ORDER BY has
to be used with SELECT.
E.g. SELECT EMP#,EMPNAME FROM EMP WHERE EMPLEVEL = ‘7’
ORDER BY EMPNAME DESC;
Here the required sequence is arranged. The ORDER BY can take either ASC or DESC. ASC is default.
E.g. SELECT EMP#,EMPNAME
FROM EMP
WHERE EMPLEVEL = ‘7’
ORDER BY 2 , DESC;
Here this will produce the same result as above . 2 refer to second column of the resultant table.
FROM EMP
WHERE EMP# = ‘8000’
OR EMP# = ‘8001’
OR EMP# = ‘8002’ ;
NOT IN can also be used to exclude the specific values.
LIKE can be used to search for a specific character or a string or a character within a string. But
when using the LIKE
The ‘-‘ stands for a single character.
The % character stands for any sequence of N characters
All other character stands for themselves
E.g. SELECT EMP#,EMPNAME
FROM EMP
WHERE EMPNAME LIKE ‘ J%’ ;
This will retrieve all rows having EMPNAME starting with J.
E.g. SELECT EMP#,EMPNAME
FROM EMP
WHERE EMPNAME LIKE ‘%J%’ ;
This will retrieve all rows having J anywhere in the EMPNAME.
E.g. SELECT EMP#,EMPNAME
FROM EMP
WHERE EMPNAME LIKE ‘---J’ ;
This will retrieve the rows with EMPNAME having 4 characters with J as ending one. Not LIKE can also
be used as in previous cases.
This is generally used to retrieve data from more than one table.
This query involves joining a table to itself. So here two references of same table are used. Here
two range variables A,B are used. These variables ranges over that specified table only.
E.g. SELECT A.S#, B.S#
FROM S A,S B
WHERE A.CITY = B. CITY;
8.4 ) SUBQUERIES
Subqueries are nested SELECT. SELECT FROM WHERE is nested within another such
expression.
e.g. SELECT S#
FROM S
WHERE CITY IN
(SELECT CITY FROM P WHERE P# = ‘P2’);
This will evaluate the nested subquery first. It will get the value of CITY.
E.g. If for P2 the CITY= PARIS
Then the above query will be same as
SELECT S#
FROM S
WHERE CITY IN (‘PARIS’);
The subquery, which is shown above, can be rewritten with a join also. Multiple levels of nesting can also
be included. In the above example in second WHERE another nesting can be added.
This is a type of subquery in which the inner and outer select statements are executed
simultaneously.
E.g., SELECT SNAME FROM S
WHERE ‘P2’ IN
( SELECT P# FROM SP WHERE S# = S. S#);
Here inner nested query requires the variable S# from table S, whose value changes when the system
examines the table S. For example initial value S1 is selected. From the inner SELECT value of P#
corresponding to S1 are obtained. Then it evaluates the outer query. The corresponding SNAME will be
selected. Thus the processing for S1 will be completed. Then it selects the next value of S# from the table S
and the processing continues. A correlated subquery is one, which whose values depend on some variable
that receives its value from outer query. Thus both the queries are simultaneously executed. So such a
subquery has to be evaluated repeatedly instead of once.
Even in the correlated subquery inner and outer queries can refer to the same table
E.g. SELECT A. P#
FROM SP A
WHERE A.P# IN
( SELECT B.P# FROM SPB WHERE B.S# = A.S#);
When using the subquery scalar comparison operators such as =,> etc can also be used.
E.g. SELECT S# FROM S WHERE CITY =
( SELECT CITY FROM S WHERE S# = ‘S1’);
A quantified comparison operator consists of a scalar comparison operator like = , >, etc followed
by ANY or ALL.
E.g. SELECT PNAME
FROMPWHEREWEIGHT>ALL
( SELECT WEIGHT FROM P WHERE COLOR = ‘BLUE’);
Here the subquery returns the weight of all parts with color blue. The outer SELECT returns the rows with
values greater than all the values of previous result.
Eg2. SELECT S# FROM S WHERE CITY = ANY
Column (Aggregate ) functions, compute from a group of rows, a single value. This provides
capability to aggregate data so as to perform statistical calculations across many rows with one SQL
statement. The column functions are
AVG Average of the values in the column
SUM Sum of the values in the column
COUNT Number of values in the column
MAX Largest value in the column
MIN Smallest value in the column
8.8 ) GROUP BY
Using this table can be grouped for taking some aggregate values.
E.g. SELECT P#, SUM(QTY)
FROM SP
GROUP BY P#;
This query will give each value of P# along with the sum of QTY for that specific value of P#.
Eg2. SELECT P#, SUM(QTY), MAX(QTY)
FROM SP
WHERE S# <> ‘S1’
GROUP BY P#;
When using GROUP BY, to specify condition HAVING is used. So in short HAVING is to
groups is what WHERE is to rows.
E.g. SELECT P#
FROM SP
GROUP BY P#
HAVING COUNT(*) > 1;
8.10 ) UNION
The UNION operates on two sets of rows and combines them together into a single set. Two sets
of rows must be union compatible. i.e. the two original sets must be of the same shape.
E.g. SELECT P# FROM P WHERE WEIGHT > 16
UNION
SELECT P# FROM SP WHERE S# = ‘S2’ ;
The duplicate rows will always be eliminated. But if the user wants all the rows to be retrieved he has to
use UNION ALL
E.g. SELECT P# FROM P WHERE WEIGHT > 16
UNION ALL
SELECT P# FROM SP WHERE S# = ‘S2’ ;
Any number of SELECT can be UNIONed together. If OREDER BY clause is used it should come as a
part of final SELECT only. In simple equijoin it select the matching rows only. But if any user want both
matching and unmatching rows from any table (Outer Join) UNION ALL can be used.
E.g. SELECT S.*,SP.P#
FROM S,SP
WHERE S.S# = SP.S#
UNION ALL
SELECT S.* ,’ ‘
FROM S
WHERE NOT EXISTS
(SELECT * FROM SP WHERE SP.S# = S.S#);
8.11 ) INSERT
8.12 ) UPDATE
E.g. UPDATE SP
SET QTY = 0
WHERE ‘LONDON’ =
( SELECT CITY FROM S
WHERE S.S# = SP. S#) ;
This uses a subqueruy
8.13) DELETE
The DELETE is used to remove row or rows that satisfy the specific condition.
E.g. DELETE FROM S WHERE S# = ‘S5’ ;
This is a single row delete as the specific condition is given. Multiple rows can also be deleted
using a single query
E.g. DELETE FROM SP WHERE QTY > 300 ;
Subquery can also be used similar to previous cases.
THE CATALOG
9.1 ) Introduction
DB2 catalog can be treated as a system database that contains information about various objects
such as base tables, views etc. Catalog in a DB2 system consists of various system tables. User can
interrogate catalog using standard facilities of SQL language. In DB2 system the catalog consist of 38
system tables. Some of these catalog tables are described below
9.2) SYSTABLES
This catalog table contains a row for every base table in the entire DB2 system. It include the
informations such as NAME of the table, CREATED BY give the user who created the table, CREATOR
which mentions the owner of the table and many other fields.
NAME CREATED BY CREATOR COLCOUNT OTHERINFOS
S JACOB JACOB 4 ------------
P JACOB JACOB 5 -------
9.3 ) SYSCOLUMNS
This catalog table contains a row for every column of each table of the system.
NAME TBNAME TBCREATOR COLTYPE ------------
S# S JACOB CHAR -------------
SNAME S JACOB CHAR ---------------
----- ----- -------- --------- --------------
9.4 ) SYSINDEXES
This catalog table contains a row for every index in the system.
NAME CREATED BY CREATOR TBNAME TBCREATOR ----------------
nameofindex JACOB JACOB S JACOB ----------
---- ----------- ---------- -- ----------- --------------
Alias is an alternate name for a base table. These will help to access the table very easily. For
example if user A create a table X and user B wants to access that table then the fully qualified name
should be given
E.g. SELECT * FROM A.X;
But if user B can create an alias and use it
E.g. CREATE ALIASE T1 FOR A.X;
SELECT * FROM T1;
Will give the same result as in the first case. Even a third user can also use the same alias by giving a fully
qualified name
E.g. SELECT * FROM B.T1;
These can be removed by using DROP statement.
E.g. DROP ALIASE T1;
A synonym is similar to an alias. But the basic difference is that it is private to the user who creates it. Also
synonym unlike alias cannot refer to remote tables.
E.g. CREATE SYNONYM S1 FOR A.X;
This can only be used by user who creates it. Also the table should not be remote. Removing the
SYNONYM can be done by
E.g. DROP SYNONYM S1;
VIEWS
10.1 ) Introduction
A view is a virtual table that consists of SQL SELECT statements, which can access the data from
base tables. A view never stores the data. But when the view is accessed the SQL statements are executed
to access the data. So the view can access data from more than one table. These views provide with several
advantages. They allow same data to be seen by different users in different ways. The users perception is
simplified because by using a view he can select only those columns that are required. More security can be
given as all the columns that are not visible in the view. View also provides with logical data
independence.
Retrieval operations on a view will be converted into equivalent operations on a base table. But in
some case like when a user tries to create a view column which is derived from something other than a
simple column of the base table it can fail.
E.g. CRETE VIEW PQ (P#, TOTQTY)
AS SELECT P# , SUM(QTY) FROM SP GROUP BY P# ;
Not all views are updatable. This is because a view can be selected from more than one base table.
Also there are chances to affect the various integrity relations. So in such case views are not updateable.
But if in some views we will be able to preserve the tables integrity relations then they are updateable.
The security has to be given for protecting against unauthorized disclosure alteration etc in the
database. Each individual user is assigned an authorization id and all the tables that are created by the user
will be owned by this id. Authorization subsystem which allows users having certain privilege to
selectively grant those privilege to others. There are different types of privileges
For performing a particular operations user must hold the appropriate authority or privilege. These
two commands are associated with granting and revoking of privileges.
The syntax of the grant statements is
GRANT privileges [ON [type] objects ] to users;
E.g. GRANT SELECT ON TABLE S TO <userid>;
Similarly the revoke statements can be used to revoke privileges.
E.g. REVOKE SELECT ON TABLE S FROM <userid>;
If a privilege is granted to user A using GRANT OPTIONS, then user A can grant the same
privilege to user B.
E.g. GRANT SELECT ON TABLE S TO A WITH GRANT OPTION;
Then user A can grant the same privilege to user B
EMBEDDED SQL
12.1 ) Introduction
SQL statements can also be used in application program. So such SQL statements which are
included in the host language program are called Embedded SQL statements. The host languages that
currently supported by DB2 are PL/I, COBOL,FORTAN,C,SYSTEM/370 Assembler language.
12.2 ) Preliminaries.
Embedded SQL statements should be prefixed by EXEC SQL. And should be terminated by a
termination symbol(e.g. END EXEC).
An executable statements can appear wherever an executable host language can appear.
SQL statements can include references to host variables. Host variables should be prefixed by a colon
which helps to identify them from SQL column names. These host variables used should declared in
BEGIN DECLARE SECTION and terminated by END DECLARE SECTION.
Host variables can appear in SQL data manipulation language where literals are permitted.(E.g. INTO
clause in SELECT, WHERE and HAVING clause where values to be compared etc.)
Any table used in the program can be declared by means of an EXEC SQL DECLARE TABLE to
make the program more self-documenting.
SQLCODE AND SQLSTATE are two special host variables to get the feedback information after the
SQL query executed. A SQLCODE zero means that statement executed successfully. If a positive
value then statements executed with some exceptional conditions and a negative value means that the
statement did not execute successfully. The SQLSTATE values consists of two character ‘class code ‘
followed by three character ‘subclass code’ .This will also helps to know whether the SQL statements
are executed successfully. So to find the status every SQL statement in the program should be followed
by a test on SQLCODE or SQLSTATE.
SQLCA or SQL Communication Area can be included so that it contains the declarations for both
SQLCODE and SQLSTATE. So either use INCLUDE SQLCA or declare SQLCODE and
SQLSTATE explicitly
Embedded SQL SELECT statement requires INTO clause specifying the host variable so that values
retrieved from database can be assigned. These host variables should have a data type compatible with
the SQL data type of columns from which the values are retrieved. Host variables and database can
have same name.
E.g. EXEC SQL
SELECT STATUS,CITY
This will select the values of STATUS and CITY in to the host variables and SQLCODE will be
set to 0. If there is no row with S#= S5 then SQLCODE will be set to 100. If there is more than a row with
S# = S5 then the program will show an error with SQLCODE negative. If the values retrieved to be null,
the user has to include an indicator variable. For example if STATUS is NULL then
E.g. EXEC SQL
SELECT STATUS,CITY
INTO :STATUS INDICATOR :STATUSIND, : CITY
FROM S
WHERE S# = ‘S5’
END-EXEC;
If the value to be retrieved to be NULL the indicator value will be set to -1 and host variable
remains unchanged. Indicator variable should be declared as 15-bit signed binary integers.
E.g. EXEC SQL
INSERT INTO P(P#, PNAME, WEIGHT)
VALUES (:PNO, :PNAME, :WEIGHT)
END-EXEC;
In the case of singleton SELECT only one row has to be selected and the retrieved values will be
moved into host variable. But in some cases more number of rows have to be selected. DB2 application
programs uses cursor to navigate through a set of rows returned by an embedded SQL SELECT statement.
Cursor is declared, opened, rows are fetched from cursor one row at a time and cursor is closed.
Four distinct operations or cursors are
12.3.1 )DECLARE
Declare defines the cursor, gives it a name unique to the program in which it is embedded and
assigns and SQL statement to the cursor name. The DECLARE statement does not execute the SQL
statement but merely defines it.
12.3.2 )OPEN
Open is an executable statement. It reads the SQL search fields, execute the SQL statement and
sometimes builds the resultant table. It does not assign values to host variables.
12.3.3)FECTCH
Returns the data from the resultant table one at a time to the specified host variables. If the
resultant table is not built at cursor open time, it is built one by one. When cursors are used for retrieving
multiple rows FETCH statement should be coded in a loop. When no more rows to be retrieved FETCH
statement should return an SQLCODE of +100.
12.3.4)CLOSE
EXEC SQL
DECLARE CURSOR C1 FOR
SELECT S# ,SNAME,STATUS
FROM S
WHERE CITY = ‘LONDON’
END-EXEC.
PROCEDURE DIVISION.
-
-
EXEC SQL
OPEN C1
END-EXEC.
IF SQLCODE < 0 PERFORM ERR-PARA.
PERFORM PARA1 UNTIL MORE ROWS = ‘N’.
EXEC SQL
CLOSE C1
END-EXEC.
ERR-PARA.
--
--
PARA1.
EXEC SQL
FETCH C1 INTO :S#, :SNAME, :STATUS
END-EXEC.
IF SQLCODE = +100
MOVE ‘N’ TO MORE ROWS.
IF SQLCODE < 0 PERFORM ERR-PARA.
More number of cursors can be opened at any time. There is no limit to the number of cursors permitted per
application program. The cursor should be declared first before doing any processing on it. Update and
Delete can also be done. These are CURRENT forms of UPDATE and DELETE but it cannot be used
when UNION,GROUP BY,ORDRER BY,DISTINCT etc are used. Also this is not used in the case of
subqueries.
E.g. EXEC SQL
DELETE FROM S
WHERE CURRENT OF C1
END-EXEC.
TRANSACTION PROCESSING
13.1) Introduction
A Transaction is a term used to specify the logical unit of work. This can involve any number of
updates in between. Thus it is a sequence of several operations which converts one consistent state of
database into another, without necessarily preserving the consistency in between. Generally explaining if
one transaction reaches its normal termination with all the steps in between working properly, then the
updation will be made permanent. Instead if some SQL ERROR or some system failure occurs, every
changes made will be erased. So it can be said that either full updation or no updation at all,but partial
updation cannot be made. These are taken care by system component called Transaction Manager.
Whenever an UPDATE is done it is not done on the database. If something goes wrong with
system, updation may be revoked either by program or by system. The data in such condition is called as
tentative until either of these happens
COMMIT
ROLLBACK
These two are not really database operations like SELECT and UPDATE. They are instructions to
Transaction Manager. A term Synchronization point will be used (Abbreviated as SYNCHPOINT) which
represents the level between two consecutive transactions.
Any updation made in the system is guarantied once it is committed. This could be by way of an
explicit COMMIT given by the program or it could be given by the system, when the task normally
terminates i.e. A successful end of a transaction is signaled as a synchpoint is established. By the way of
COMMIT statement all open cursors will be closed and all record locks will be released.
The SQL COMMIT statement takes the form
COMMIT [work];
ROLLBACK can also be given explicitly in the program or will be issued by the system when the
task abnormally terminates. Here all updations done after the previous SYNCHPOINT will not be saved to
database. Here again all open cursors are closed and record locks are released.
The syntax is
ROLLBACK[work];
DB2 being a shared system allows numerous users to access the same database simultaneously.
Any such kind of system requires some kind of control mechanism to ensure that concurrent transaction do
not interfere with each others operation. There are essentially three ways in which things can go wrong.
They are
The lost update problem
The uncommitted dependency problem
The inconsistent analysis problem
This occurs when one transaction is allowed to retrieve a row that has been updated by another
transaction and has not yet been committed to database by other transaction.
13.4) Solution.
For solving the concurrency issues technique called Locking is used. The idea of locking is that
when transaction needs to update an object it puts a lock on that object. The effect of this is to lock the
other transactions out of the object thereby preventing any changes on it. These locks can be either shared
lock or exclusive lock.
Though DB2 provides implicit locking mechanism locking can also be done by explicit
declarations.
The syntax is
E.g. LOCK TABLE SP IN SHARE MODE.
Eg1. LOCK TABLE P IN EXCLUSIVE MODE.
Where the table should be a base table and not a view. This command acquires an S or X lock on
the entire table as per the command given. Acquiring such lock may not be instantaneous since the program
will have to wait for a time, when all table level locks will be removed. Once this is done table level locks
will be made and if it is a shared one then the other transactions will be able to get shared locks on any
levels.
The ISOLATION parameter on BIND command specifies, isolation level for the application plan
being bound. The two options are
REPETABLE READ
CURSOR STABILITY
13.5.2.1)CURSOR STABILITY
Repeatable Read. Here if a transaction obtains an addressability to record under CS and if there is a
possibility that the transaction may update the record, i.e. the cursor is defined FOR UPDATE, then DB2
issues a Update Lock (ULOCK) for the transaction instead of the X lock. If a transaction holds a U lock
and another transaction requests for a U lock or X lock the request will be put in the wait state. If the first
transaction updates the record, the U lock will be changed to X lock else it will be released when the
addressability is removed. The advantage here is formation of dead locks may be avoided.
13.5.3)LOCK SIZE
For a given table space, the lock size can be specified as PAGE, TABLE, TABLESPACE or ANY
depending on the factor in the CREATE or ALTER TABLE SPACE operation. When TABLE is specified,
locking will be in the table level and when PAGE is specified, locking will be in the page level, when ANY
is specified DB2 itself decides which unit of locking would be optimum. Mostly DB2 acquires page level
lock initially and when the number of page level lock reaches a installation specified threshold value, then
DB2 escalates the level locking to a higher factor.
These parameters in the bind statement specifies when a table space level lock will have to be
acquired or released. For ACQUIRE possible specifications are USE And ALLOCATE, for RELEASE it
is COMMIT and DEALLOCATE. USE means that the Lock is acquired on the first use and ALLOCATE
means that the locks are allocated when the program begins execution. COMMIT means that the table
space level locks are released at each synch point, and in DEALLOCATE the locks will be held until the
program terminates.
13.6) DEADLOCK
It appears when two or more transactions are simultaneously in the wait state when one transaction
waits for the resource held by another while the other waits for the resource held by the first transaction.
When such a condition occurs, there is no other alternative except to detect it and break it. The breaking
part involves choosing one of the deadlock transaction as the victim and either rolling it back or asking it
role back. This releases the deadlock.
DYANAMIC SQL
14.1)Introduction
Dynamic SQL consists of a set of embedded SOL facilities, that are provided specifically to allow
the construction of generalized on line application. There may be a necessity some times to construct the
required SQL statements dynamically and then to bind and create those constructive statements
dynamically. DB2I is a generalized on-line application, which can accept any valid SQL statements . It uses
the facility of Dynamic SQL to construct suitable SQL statements corresponding to its input, bind and
execute this statements and to return messages and results back to the terminal.
There are different types of Non SELECT Dynamic SQL statements. They are
PREPARE/ EXECUTE
EXECUTE IMMEDIATE
14.2) PREPARE/EXECUTE
This class of Dynamic SQL uses PREPARE and EXECUTE to issue SQL statements. Non SELECT
Dynamic SQL cannot issue a SELECT statement.
Eg1.
WORKING-STORAGE SECTION.
-
-
EXEC SQL INCLUDE SQLCA END-EXEC.
01 STRING-VAR.
02 STRING-VAR-LEN PIC S9(4) COMP.
02 STRING-VAR-TEXT PIC X(100).
PROCEDURE DIVISION.
MOVE 39 TO STRING-VAR-LEN.
MOVE “DELETE FROM TAB1 WHERE DEPTNO = ‘A00’” TO STRING-VAR-TEXT.
EXEC SQL
PREPARE STMT1 FROM :STRING-VAR
END-EXEC.
EXEC SQL
EXECUTE STMT1
END-EXEC.
EXECUTE IMMEDIATE which combines the functions of both PREPARE and EXECUTE
statements.
E.g. WORKING-STORAGE SECTION.
-
-
EXEC SQL INCLUDE SQLCA END-EXEC.
01 STRING-VAR.
02 STRING-VAR-LEN PIC S9(4) COMP.
02 STRING-VAR-TEXT PIC X(100).
PROCEDURE DIVISION.
MOVE 39 TO STRING-VAR-LEN.
MOVE “DELETE FROM TAB1 WHERE DEPTNO = ‘A00’” TO STRING-VAR-TEXT.
ADMINISTRATION FACILITIES
15.1) Introduction
This falls into two categories. They are facilities for database and facilities for system
administration. The database administration involves the design implementation and maintenance of
individual DB2 database and associated application. Two DB2 features that can assist these tasks are
DB2I and EXPLAIN facility. The system administration covers the installation, monitoring, tuning and
control of overall DB2 system itself.
Almost all functions of DB2 are available online through the DB2 interactive interface. This
provides the ability to execute SQL statements interactively and to invoke pre-written application
programs. Apart from this they also have ability to issue operator commands, the ability to invoke database
utilities and the ability to prepare application programs for execution. Though DB21 is the normal mode of
operation, it is always possible to use batch. TSO supports both batch and online application. The online
application work under the control of ISPF. DB2I itself is a TSO online application, which provides the
ability to execute SQL statements interactively by means of a component call SPUFI (SQL Processor Using
File Input).
The following are the sequence of events for invoking DB2I
DB2I Defaults
Exit
15.2.1) SPUFI
This reports the interactive execution of SQL statements from TSO terminals. The idea here is that
the user can create a text file containing one or more SQL statements then execute the statement through
SPUFI and then use ISPF browse to browse the result.
15.2.2) DCLGEN
This allows the user to invoke the Declaration Generator program. This is the program that creates
embedded SQL, DECLARE TABLE statements and corresponding host language structure declarations
from table description in the catalog. The output from this is stored as a modules of a PDS which could be
copied by the include statement or to put up in the program itself.
15.2.3)Program Preparation
This allows the user to perform any of the following or all of the following functions.
Precompilation
Compilation or assembly
Linkage editor processing
Bind processing
Program execution (TSO application only)
15.2.4)Precompile
This is effective only for the precompile step of the program preparation .
BIND creates the application plan from one or more DBRM'S. The following parameters may be specified.
If the new plan is to replace the existing one
The AUTH ID that is to own the plan if that ID is different from the ID of the user entering the bind
command.
The isolation level RR & CS specifies the lock acquisition and release times for the plans.
REBIND rebinds the existing plan. It is not a replace version of the bind command. Here the input for the
rebind command is the previous plan but not the DBRM.
15.2.5) RUN
This allows the user to enter system operator commands like START DATABASE, STOP
DATABASE etc.
15.2.7)Utilities
15.2.8)Catalog Visibility
Catalog Visibility menu allows certain queries to be formulated against DB2 catalog with out
direct use of SQL.
This menu allows the user to set certain defaults for DB2I session
15.2.10) EXIT
15.3) EXPLAIN
This allows the user to obtain information regarding the operators choice for the access strategy
specified for the SQL statement.
E.g. EXPLAIN PLAN FOR
SELECT SNO, NAME
FROM TAB
WHERE CITY = PUNE
The DB2 database utilities are all online utilities and can be invoked online without stopping the
execution of DB2 system. Some of them are.
CHECK This utility checks a table space to find if there are any referential integrity violation. Records
if found to contain any unmatched foreign key value, the table space will be in the check pending state.
COPY This utility creates a full or incremental back-up copy of the table space. An incremental copy is
a copy of the pages that have changed since the previous change
LOAD This utility loads data from a sequential data set into one or more tables with one or more
partitions of a specified table space.
MERGE COPY This utility merges a full copy and one or more incremental copies to produce a upto
date full copy.
MODIFY This is used to perform maintenance operation recovery information in the DB2 catalog.
RECOVER This uses the most recent full copy, any subsequent incremental copies, and any
subsequent log data to recover one or more table space partitions or pages after a media failure
REPAIR This can be used to reset conditions like check pending.
REPORT This produces some reports that are useful in connection with managing database recovery
process
RUNSTATS This computes statistics on specified stored data and writes them to the system catalog.
STOSPACE This gathers information regarding the amount of space allocated to a given set of table
space and indexes and stores them in a DB2 catalog.