You are on page 1of 138

DB2/OS390 Database Class

7/10/2011

>

EXIT

DB2 Version 5.1

7/10/2011

<

>

MAIN MENU

EXIT

DB2 CLASS OUTLINE MAIN MENU


Brief Discussion of Relational Database DB2 Physical Structures DDL - Data Definition Language DCL - Data Control Language DML - Data Manipulation Language DB2 Internal Functions DB2 Commands & Utilities Appendixes 7/10/2011

Relational Database Physical Structures DDL DCL DML DB2 Internals Commands/Utilities Appendixes

<

>

EXIT

RELATIONAL DATABASE Basic Elements


DB2 (MVS) Version 1 introduced in 1983. Built on Dr. Codd's Relational Database Model. First Basic Element: Table

In which columns represent things and the attributes that describe them; and rows that represent specific instances or occurrences of the thing described. Second Basic Element: Operators (SQL Language) Structured procedure for defining, controlling, manipulating, and retrieving information from a database (i.e. table).
Note - SQL (Structured Query Language) consists of: DDL (Data Definition Language), DCL (Data Control Language), and DML (Data Manipulation Language.
7/10/2011

<

>

MAIN MENU

EXIT

DB2 KEY COMPONENTS


MVS Subsystem Environments:

TSO - contains a teleprocessing monitor; programs may be online or batch and may not access IMS databases. IMS - contains a teleprocessing monitor (IMS/DC or IMS/TM) and may access DB2 and IMS databases either online or batch. CICS - contains a teleprocessing monitor and may access DB2 and IMS databases online only.

7/10/2011

<

>

MAIN MENU

EXIT

DB2 KEY COMPONENTS


Primary Online Facilities:

QMF - Query Management Facility uses the Call Attach Facility to attach to DB2. Used to enter dynamic SQL against DB2 objects. DB2I - DB2 Interactive is attached through TSO and is also used to enter dynamic SQL against DB2 objects. Also contains additional control features for DB2 commands and utilities.

7/10/2011

<

>

MAIN MENU

EXIT

DB2 PHYSICAL STRUCTURES

7/10/2011

<

>

MAIN MENU

EXIT

DB2 Object Hierarchy

7/10/2011

<

>

Physical Structures

EXIT

DB2 Object Terminology


Database - Related Tables and Indexes and their spaces, grouped to
facilitate handling.

Tablespace - An area of External Storage assigned to hold a table. Table - Actual Rows and Columns of Data. Index - Consists of one or more VSAM datasets used to achieve more
efficient access to data pages and/or to ensure row uniqueness.

Synonym - An alternate, private name for a table or view. View - A logical, column-filtered, representation of a table. columnAlias - A type of global synonym for a table.
7/10/2011

<

>

Physical Structures

EXIT

DB2 Table/Tablespace Relationship


A Page is the unit of transmission. A Row must be contained within a single page. A Page may contain several rows. Page size is 4096 bytes. Tablespace, Table, Page, Tablespace, Table, Page, and Row are units of locking. Maximum Tablespace size is 1016 Gigabytes. A Segmented Tablespace contains equal-sized segments of from 4 to 64 pages equalin multiples of 4 pages. All pages in a segment contain rows of only one table. A Non-Partitioned Tablespace (simple or segmented) can contain one or more Nontables. A Partitioned Tablespace can contain only one table and cannot be segmented.
7/10/2011

<

>

Physical Structures

EXIT

SIMPLE Tablespace

Data Page

Multiple tables can be assigned to a single simple (non-partitioned unsegmented) tablespace. - Intermix rows of highly related tables for performance - Rows are interleaved in the tablespace in the sequence that they are inserted/loaded.
7/10/2011

<

>

Physical Structures

EXIT

PARTITIONED Tablespace
PARTITION 1 3032210001 3032210002 3032210005 PART 1 Values (3039999999)

PARTITION n 5053420001 5053420003 5053420004

PART n Values (5059999999)

n = 2 - 64 Partitions. Must have a Clustering Index. Each partition (tablespace and indexspace) is a separate dataset. Partition Independence - Utilities can be run by partition.
7/10/2011

<

>

Physical Structures

EXIT

SEGMENTED Tablespace
Segment 1 Segment 2

Table A Rows

Table B Rows

Minimize datsets and associated management. Minimize data unavailability (lock contention). Minimize mass update/delete/insert time. Minimize table scan time. Clustering index clusters rows by table.
7/10/2011

<

>

Physical Structures

EXIT

Tablespace Format SEGMENTED


Data Page n+1
Space Map Page

Data Page n

Data Page 1
Space Map Page

Header Page

7/10/2011

<

>

Physical Structures

EXIT

DB2 Data Page


Page Header 20 Bytes

Row Header 6 Bytes

Row Data

RID (Row ID)

Row Header 6 Bytes

Row Data

RID ID Map: 2 Bytes/Row


7/10/2011

<

>

Physical Structures

EXIT

SEGMENTED TABLESPACE Space Map Page


Page Header 26 Bytes SPACE MAP OF SEGMENT ENTRIES: One per segment (SEGBLK) 7 bytes of control information plus 4 bits per page in segment free space in page.

MODIFIED PAGE INDICATORS (One Bit Per Page)


1 Byte Trailer

For 4K Pages, a Space Map controls 1712 pages for Segment Size of 4 ... up to 5504 pages for Segment Size of 64.
7/10/2011

<

>

Physical Structures

EXIT

SEGMENTED Indexspace Format


Index Page n+1
Space Map Page

Index Page n

Index Page 1
Space Map Page

Header Page

1 Space Map Page per 32,632 Pages 7/10/2011

<

>

Physical Structures

EXIT

DB2 Index Leaf Page


Physical Header 28 Bytes Logical Header 17 Bytes Key RID
Indexed Column(s) Page # - 4 bytes ID # - 1 byte

Subpage Directory (4 bytes + keylength) Key


Max. 254 Bytes

RID
5 Bytes

Key

RID

Free Space

1 Byte Trailer

7/10/2011

<

>

Physical Structures

EXIT

DB2 Index Structure


ROOT PAGE

NON LEAF PAGE

NON LEAF PAGE

Balanced Tree

LEAF PAGE

LEAF PAGE

LEAF PAGE

7/10/2011

DATA PAGES < > Physical Structures EXIT

DB2 Index Terminology


Clustering - Maintaining the order of data pages to match the index. Unique - Only one value for that column or columns. NonNon-Unique - Duplicates allowed. Partitioned - The partition is determined by a range of values for
this type of index.

NonNon-Partitioned - Not dependent on any partition; includes the


entire table.

Primary Key - Indicates Referential Integrity; i.e. Parent Table. Integrity; Foreign Key - Indicates Referential Integrity; i.e. Dependent (or Integrity;
Child) Table.
7/10/2011

<

Physical Structures

EXIT

DDL (Data Definition Language)


CREATE - Database, Tablespace, Table, Index,
Synonym, View, Alias, Stogroup
CREATE DDL

ALTER - Tablespace, Table, Index, Stogroup DROP - Database, Tablespace, Table, Index,
Synonym, View, Alias, Stogroup

ALTER DDL

DROP DDL

7/10/2011

MAIN MENU

EXIT

CREATE DATABASE
A DATABASE is related tables and indexes and their spaces grouped to facilitate handling.
CREATE DATABASE CRISAPDB STOGROUP CRISGRP1 BUFFERPOOL BP0

Note: No ALTER DATABASE

7/10/2011

>

DDL

EXIT

CREATE TABLESPACE
A TABLESPACE is an area of external storage assigned to hold a table.
CREATE TABLESPACE CRISAPTS IN CRISAPDB USING STOGROUP CRISGRP1 PRIQTY 180000 (in Kbytes) SECQTY 3600 (in Kbytes) ERASE NO (binary 0 overwrite) LOCKSIZE ANY (also Page or Tablespace) BUFFERPOOL BP0 (60 available buffers) CLOSE NO FREEPAGE 63 (after every 63, 1 empty) PCTFREE 10 (free space on each page) SEGSIZE 64
< > DDL EXIT

7/10/2011

3390 EQUIVALENT DASD


12 - DB2 4K Pages per Track 15 - Tracks per Cylinder 256 - VSAM Extents per Dataset (Version 5.1) FA;3.7

File-AID/SPF - Utility VTOC list for DD3I61 (3390) -------- 10 DATASETS LISTED COMMAND ===> SCROLL ===> CSR VTOC: 209 Tracks ( 1 %Used) 10432 Free DSCB'S 10 Data sets VOL: 50085 Tracks ( 35 %Used) 15 Tracks/cylinder 15 ALT Tracks FREE: 2165 Cyls (MAX= 2163) 32494 Trks (MAX= 32445) 4 Free Xtnts --------- D A T A S E T N A M E ---------- Org Trks %Used XTS= Status DRM.DSNDBD.XYPRV00D.XYPRVPSS.I0001.A001 VS 30 ? 1 DRM.DSNDBD.XYPRV00D.XYPRVPS0.I0001.A001 VS 3 ? 2 DRM.DSNDBD.XYPRV00W.XYPRVPSS.I0001.A001 VS 6 ? 5 DRM.DSNDBD.XYPRV00W.XYPRVPS0.I0001.A001 VS 2 ? 1 DRMCRB0D.DSNDBD.MTRCB00D.MTRCBSIS.I0001.A001 VS 12000 ? 1 DRMSVO0D.DSNDBD.MX5AD00D.MX5AD020.I0001.A001 VS 2220 ? 12 DRMSVO0D.DSNDBD.MX5BF00D.MX5BF010.I0001.A001 VS 675 ? 37 DRMSVO0D.DSNDBD.MY5SO00D.MY5SOBRS.I0001.A001 VS 2400 ? 8 SYS1.VTOCIX.DD3I61 PS 15 100 1 SYS1.VVDS.VDD3I61 VS 30 ? 1 ******************************* Bottom of data ********************************

7/10/2011

<

>

DDL

EXIT

CREATE TABLE
CREATE TABLE CORPD000.CRISAPTT (CUST_ACCT_ID CHAR(24) UNIV_SRV_ORD_CD CHAR(5) PROD_INTRNL_SER_ID CHAR(10) NOT NULL, NOT NULL, NOT NULL,

. . .
PROD_DISC_DAT DATE NOT NULL) (optional referential constraints) IN CRISAPDB.CRISAPTS
7/10/2011

<

>

DDL

EXIT

DB2 TABLE (Example)


CORPD000.CRISAPTT
CUST_ACCT_ID UNIV_SRV_ORD_CD J5202810165841 J5202810197677 J5202810197677 J5202810197677 J5202810197677 J5202810420627 J5202810420627 J5202810572948 J5202810585640 J5202810585640 J5202810602687
7/10/2011

PROD_INTRNL_SER_ID PROD_DISC_DAT 5201400470 5201408956 5201408957 5201408958 5201408959 5202810420 5201408916 5201408840 5201408808 5201408809 5202810602 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31 2099-12-31

WAXSQ WAXSQ WAXSQ WAXSQ WAXSQ CPERN WAXSQ WAXSQ WAXSQ WAXSQ PYKMN

<

>

DDL

EXIT

CREATE INDEX
CREATE UNIQUE INDEX CORPD000.CRISAPT1 ON CORPD000.CRISAPTT (CUST_ACCT_ID PROD_DISC_DAT ASC, DESC) (default Ascending) (Descending) (in Kbytes) (in Kbytes) (Assigned Bufferpool) (after 31 pages, 1 empty) (freespace on the index page) (only one per table)

USING STOGROUP CRISGRP2 PRIQTY 54000 SECQTY 9000 ERASE NO BUFFERPOOL BP2 CLOSE NO FREEPAGE 31 PCTFREE 20 CLUSTER
7/10/2011

Note: Duplicate values are not allowed for this index key.
< > DDL EXIT

PARTITIONING
1. CREATE TABLESPACE CRSPARTS IN CRSPRTDB NUMPARTS 4 (no. of partitions) USING STOGROUP CRISGRP3 PRIQTY 9000 (in Kbytes) SECQTY 900 (in Kbytes) BUFFERPOOL BP0 (Assigned Bufferpool) CLOSE NO FREEPAGE 15 (after 15 pages, 1 empty) PCTFREE 10 (freespace on the data page) 2. CREATE TABLE CORPD000.CRSPARTT ... IN CRSPRTDB.CRSPARTS
7/10/2011

<

>

DDL

EXIT

PARTITIONING
3. CREATE INDEX CORPD000.CRSPARTI ON CORPD000.CRSPARTS USING STOGROUP CRISGRP4 PRIQTY 360 SECQTY 180 CLUSTER (PART 1 VALUES(wwwwwww), PART 2 VALUES(xxxxxxxxxx), PART 3 VALUES(yyyyyyyyyy), PART 4 VALUES(zzzzzzzzzzz)) CLOSE NO BUFFERPOOL BP9
7/10/2011

<

>

DDL

EXIT

CREATE VIEW
A VIEW is a logical, column-filtered, representation of a table.
CREATE VIEW CRISAPTV (CUST_ACCT_ID, UNIV_SRV_ORD_CD) AS SELECT CUST_ACCT_ID, UNIV_SRV_ORD_CD FROM CORPD000.CRISAPTT Note: No ALTER for VIEW. Also: A View cannot contain an ORDER BY, UNION, FOR UPDATE OF.
7/10/2011

<

>

DDL

EXIT

CREATE SYNONYM
A SYNONYM is an alternate name for a table or view and can be accessed only by their creator.
CREATE SYNONYM CRISSYNY FOR CORPD000.CRISAPTT

Note: No ALTER for SYNONYM

7/10/2011

<

>

DDL

EXIT

CREATE ALIAS
An ALIAS is a locally defined name for a table or view in the same local DB2 subsystem or in a remote DB2 Subsystem. Aliases can be accessed by users other than their creator.
CREATE ALIAS CRISAPTA FOR DBJM.CORPD000.CRISAPTT

Note: No ALTER for ALIAS

7/10/2011

<

DDL

EXIT

ALTER TABLESPACE
ALTER TABLESPACE CRISAPTS USING STOGROUP CRISGRP1 PRIQTY 180000 (in Kbytes) SECQTY 3600 (in Kbytes) ERASE NO (binary 0 overwrite) LOCKSIZE ANY (also Page or Tablespace) BUFFERPOOL BP8 (60 available buffers) CLOSE NO FREEPAGE 63 (after every 63, 1 empty) PCTFREE 15 (free space on each page) Note - SEGSIZE is not alterable.

7/10/2011

>

DDL

EXIT

ALTER TABLE
ALTER TABLE CORPD000.CRISAPTT (add a column)

ADD PROD_DAT DATE NOT NULL WITH DEFAULT

(optional referential constraints)

Note: NOT NULL disallowed when adding column.

7/10/2011

<

>

DDL

EXIT

ALTER INDEX
ALTER INDEX CORPD000.CRISAPT1 USING STOGROUP CRISGRP2 PRIQTY 54000 (in Kbytes) SECQTY 9000 (in Kbytes) ERASE NO BUFFERPOOL BP9 (Assigned Bufferpool CLOSE NO FREEPAGE 31 (after 31 pages, 1 empty) PCTFREE 10 (freespace on the index page) Note - SUBPAGES and CLUSTER not alterable.

7/10/2011

<

DDL

EXIT

DROP
The DROP statement deletes a DB2 object. Except for storage groups and aliases, any objects that are directly or indirectly dependent on that object are also deleted. Whenever an object is deleted , its description is deleted from the catalog and any plans or packages that refer to the object are invalidated.

7/10/2011

>

DDL

EXIT

DROP
DROP ALIAS DATABASE INDEX STOGROUP SYNONYM TABLE TABLESPACE VIEW PACKAGE alias-name database-name index-name stogroup-name synonym table-name database-name.tablespace-name view-name collection-id.package-id VERSION version-id

Note - need owner, DBADM, SYSCTRL, or SYSADM. Remember the cascade effect of dropping objects!
7/10/2011

<

DDL

EXIT

DCL (Data Control Language)

GRANT - Privileges Revoke - Privileges

GRANT DCL

REVOKE DCL

7/10/2011

MAIN MENU

EXIT

GRANT
The GRANT statement allows privileges to authorization IDs. There is a separate form of the statement for each of these classes of privileges: Collection Database Package Plan System Table/View Use

7/10/2011

<

>

DCL

EXIT

GRANT
GRANT authorization-specification TO authorization-name PUBLIC (WITH GRANT OPTION) authorization-specification Names one or more privileges in one of the formats described later. authorization-name One or more authorization IDs. PUBLIC Grants the privileges to all users
7/10/2011

<

>

DCL

EXIT

GRANT (Collection Privileges)


GRANT CREATE IN COLLECTION collection-id PACKADM ON * TO authorization-name PUBLIC (WITH GRANT OPTION)
CREATE IN Grants the BIND privilege to create packages in designated collections. PACKADM ON Grants package administrator authority for the designated collections. COLLECTION collection-id Identifies the collections on which the specified privilege is granted. COLLECTION * Indicates that the specified privilege is granted on all collections. 7/10/2011

<

>

DCL

EXIT

GRANT (Database Privileges)


GRANT DBADM ON DATABASE database-name DBCTRL DBMAINT CREATETAB CREATETS DISPLAYDB DROP IMAGCOPY LOAD RECOVERDB REORG REPAIR STARTDB STATS STOPDB TO authorization-name PUBLIC (WITH GRANT OPTION) 7/10/2011

<

>

DCL

EXIT

GRANT (Database Privileges)


DBADM - Database administrator authority. DBCTRL - Database control authority. DBMAINT - Database maintenance authority. CREATETAB - Create new tables privilege. CREATETS - Create new tablespaces privilege. DISPLAYDB - Issue DISPLAY DATABASE command. DROP - DROP/ALTER DATABASE privilege. IMAGCOPY - COPY, MERGECOPY, QUIESCE, MODIFY privilege. LOAD - LOAD utility privilege. RECOVERDB - RECOVER and REPORT utility privilege. REORG - REORG utility privilege (tablespace & indexes). REPAIR - REPAIR and DIAGNOSE utility privilege. STARTDB - Issue START DATABASE command. STATS - RUNSTATS and CHECK utility privilege. STOPDB - Issue STOP DATABASE command.

7/10/2011

<

>

DCL

EXIT

GRANT (Package Privileges)


GRANT ALL ON PACKAGE/PROGRAM BIND , COPY , EXECUTE/RUN collection-id.package-id * TO authorization-name PUBLIC (WITH GRANT OPTION)

7/10/2011

<

>

DCL

EXIT

GRANT (Package Privileges)


BIND - Grants the BIND and REBIND privilege. COPY - Grants the COPY option privilege of the BIND subcommand. EXECUTE/RUN - Grants the privilege to run the program. ALL - Grants all privileges for which you have grant authority. collection-id.package-id - explicitly identifies a single package. collection.* - applies to every package in the collection.

7/10/2011

<

>

DCL

EXIT

GRANT (Plan Privileges)


GRANT BIND ON PLAN EXECUTE TO authorization-name PUBLIC (WITH GRANT OPTION) plan-name

BIND - Grants the BIND, REBIND and FREE privilege. EXECUTE - Grants the privilege to run programs using this plan. plan-name - Identifies the application plan.

7/10/2011

<

>

DCL

EXIT

GRANT (System Privileges)


GRANT ARCHIVE BINDADD BINDAGENT BSDS CREATEALIAS CREATEDBA CREATEDBC CREATESG DISPLAY MONITOR1 MONITOR2 RECOVER STOPALL STOSPACE SYSADM SYSCTRL SYSOPR TRACE

TO authorization-name PUBLIC (WITH GRANT OPTION)

7/10/2011

<

>

DCL

EXIT

GRANT (System Privileges)


ARCHIVE - ARCHIVE LOG command privilege. BINDADD - Create plans and packages with BIND subcommand. BINDAGENT - BIND, REBIND, FREE/DROP package privilege. BSDS - RECOVER BSDS command privilege. CREATEALIAS - CREATE ALIAS . CREATEDBA - CREATE DATABASE authority ( DBADM). CREATEDBC - CREATE DATABASE authority (DBCTRL). CREATESG - Create new strorage groups privilege. DISPLAY -DISPLAY bufferpool, database, thread, trace, location. MONITOR1 - Privilege to obtain IFC data. MONITOR2 - Privilege to obtain IFC data. RECOVER - RECOVER INDOUBT command privilege. STOPALL - STOP DB2 command privilege. STOSPACE - STOSPACE utility privilege. SYSADM - Grants all DB2 privileges. SYSCTRL - Same as SYSADM without read/update of user data. SYSOPR - System operator authority. TRACE - START, MODIFY, STOP TRACE command privilege. 7/10/2011

<

>

DCL

EXIT

GRANT (Table/View Privileges)


GRANT ALL ON table-name/view-name ALTER DELETE INDEX INSERT SELECT UPDATE (column-name) TO authorization-name PUBLIC (WITH GRANT OPTION)

7/10/2011

<

>

DCL

EXIT

GRANT (Table/View Privileges)


ALL ALTER DELETE INDEX INSERT SELECT UPDATE - All table or view privileges. - ALTER TABLE privilege. - DELETE statement privilege. - CREATE INDEX privilege. - INSERT statement privilege. - SELECT statement privilege. - UPDATE statement privilege.

column-name - Column specific UPDATE authority.


7/10/2011

<

>

DCL

EXIT

GRANT (Use Privileges)


GRANT USE OF BUFFERPOOL bpname ALL BUFFERPOOLS STOGROUP sgname TABLESPACE dbname.tsname TO authorization-name PUBLIC (WITH GRANT OPTION)

7/10/2011

<

>

DCL

EXIT

GRANT (Use Privileges)


BUFFERPOOL bpname Allows use of this buffer for CREATE/ALTER TABLESPACE/INDEX. ALL BUFFERPOOLS Grants the privilege to refer to any buffer pool in a CREATE/ALTER TABLESPACE/INDEX. STOGROUP sgname Allows use of specified storage group for CREATE/ALTER TABLESPACE/INDEX. TABLESPACE dbname.tsname Allows reference to the specified tablespace in CREATE TABLE.
7/10/2011

<

DCL

EXIT

REVOKE
The REVOKE statement revokes privileges from authorization IDs. There is a separate form of the statement for each of these classes of privileges (see GRANT syntax): Collection Database Package Plan System Table/View Use

7/10/2011

>

DCL

EXIT

REVOKE
REVOKE authorization-specification FROM authorization-name PUBLIC BY authorization-name

authorization-specification Names one or more privileges in one of the referred to formats. authorization-name One or more authorization IDs. PUBLIC Revokes a grant of privileges to PUBLIC.
7/10/2011

<

DCL

EXIT

DML (Data Manipulation Language)

INSERT UPDATE DELETE COMMIT SELECT -

INSERT UPDATE DELETE COMMIT SELECT

7/10/2011

>

MAIN MENU

EXIT

INSERT
The INSERT statement inserts rows into a table or view. Inserting a row into a view also inserts a row into the table on which the view is based. The view may not be a Join View.
INSERT INTO table-name view-name ( column-name ,)

VALUES(host-variable) constant/literal NULL special-register subselect


7/10/2011

<

>

DML

EXIT

INSERT
INSERT (continued) table-name view-name column-name host-variable constant/literal NULL special-register subselect - name of the table. - logical name of the table. - unqualified column name of table. - output variable with an assigned value. - specifies a value( string/numeric). - represents the the null value. - specially defined storage area. - set of rows from a result set of a subselect.

Note - need INSERT, owner, DBADM, or SYSADM Authority.

7/10/2011

<

>

DML

EXIT

MASS INSERT
The mass INSERT can have a real impact on runtime performance. If the inserts are based on an ever increasing/ascending key, each time the index page becomes full that page is split with half of the entries staying and half moving to the new index page resulting in a large number of half-filled index pages and a lot of wasted DASD. Prior to Version 3.1, this type of mass insert also resulted in trackat-time pre-formatting by DB2 which further increased runtimes. In Version 4.1, this movement of half of the index entries no longer occurs and DB2 merely starts inserting into the next index page.

7/10/2011

<

>

DML

EXIT

MASS INSERT
If the inserts are more random, the deciding factors on performance become the amount of freespace on both the data pages and the index pages and synchronous (or random) I/O. If insufficient freespace exists (both percent free and freepage), the page splits that occur can make for very disorganized data. DB2 I/O Wait Time can be a large part of the overall runtime (ex. 225,000 synchronous I/O at 16 msec per I/O represents 1 hour of wait time). Faster DASD (i.e. EMC or High-Cached Iceberg) has helped reduce the effect of large numbers of synchronous I/O. With an average I/O in the 4 - 7 msec range, the same 225,000 synchronous I/O now takes around 20 minutes instead of 60 minutes. Also, Version 3.1 contained what is called an INSERT Procedure that is part of the DB2 internal code which made mass inserting much faster.
7/10/2011

<

>

DML

EXIT

UPDATE
The UPDATE statement updates the values of specified columns in rows of a table or view. Updating a row of a view also updates that row of the table on which the view is based. The view may not be a Join View.
UPDATE table-name view-name SET column-name=expression NULL ,

WHERE search-condition (Searched Update) WHERE CURRENT OF cursor-name (Positioned Update)


7/10/2011

<

>

DML

EXIT

UPDATE
UPDATE (continued) table-name view-name column-name expression NULL search-condition cursor-name - name of the table. - logical name of the table. - unqualified column name of table. - specifies a value (not a column function). - represents the null value. - combination of operators and predicates. - identifies the declared cursor.

Note - need UPDATE, owner, DBADM, or SYSADM Authority.


7/10/2011

<

>

DML

EXIT

MASS UPDATE
The mass UPDATE can have a real impact on runtime performance. If the table contains variable length rows (i.e. contains columns defined as VARCHAR or the table has compression turned on), when a column(s) is changed/updated, the row may not fit on the same page which requires DB2 to find another page on which to place it. This causes DB2 to delete the old row from the old page and insert the row on a new page. Freespace, again plays an important part in whether the row is now situated very far from the old page which affects the organization of the overall table. Without suitable freespace, the cluster ratio of the data decreases rapidly and subsequent SQL may suffer performance degradation.
7/10/2011

<

>

DML

EXIT

MASS UPDATE
DO NOT UPDATE columns that are part of an index. This also causes DB2 to delete and re-insert the rows. A different way to look at it is don't include columns in an index that may undergo frequent updating. Version 4.1 included an UPDATE Procedure to help speed-up the mass updates. Also, in Version 4.1, UPDATEs can take advantage of Dynamic Prefetch.

7/10/2011

<

>

DML

EXIT

DELETE
The DELETE statement deletes rows from a table or view. Deleting a row from a view also deletes that row from the table on which the view is based. The view may not be a Join View.
DELETE FROM table-name view-name WHERE search-condition (Searched Delete) WHERE CURRENT OF cursor-name (Positioned Delete) table-name view-name search-condition cursor-name
7/10/2011

- name of the table. - logical name of the table. - combination of operators and predicates. - identifies the declared cursor.

Note - need DELETE, owner, DBADM, or SYSADM Authority.


< > DML EXIT

MASS DELETE
The mass DELETE can have a real impact on runtime performance. If the tablespace is defined as SIMPLE or PARTITIONED (which is just a set of simple tablespaces), a mass delete (i.e. DELETE FROM TABLE-NAME with no WHERE CLAUSE - which deletes all rows) from a large table will run a long time and put quite a stress on the DB2 logs as each delete is logged. In this case, a far better way to delete all the rows of this type of table is to use the LOAD utility and load an empty dataset. The table is almost instantly (even magically) empty. If it is not desired to delete all rows, then run an UNLOAD of all the rows to keep; then run a LOAD (REPLACE) with that unloaded dataset.
7/10/2011

<

>

DML

EXIT

MASS DELETE
If the tablespace is defined as SEGMENTED, a mass delete is very fast because only the SPACE MAP pages are updated to reflect all the deleted rows. Again, if it is not desired to delete all rows (but a high percentage of the rows), use the UNLOAD/LOAD procedure previously outlined. In Version 4.1, DELETEs could take advantage of Dynamic Prefetch.

7/10/2011

<

>

DML

EXIT

COMMIT
The Unit Of Recovery in which the statement is executed is ended and a new unit of recovery is started for the process. All changes made during the unit of recovery are committed.

COMMIT WORK

JUST DO IT!
7/10/2011

<

>

DML

EXIT

SELECT
The SELECT INTO statement produces a result table containing at most one row and assigns the values in that row to host variables. If the result table is empty, the statement assigns +100 to SQLCODE and does not assign any value to the host variables.
select-clause INTO host-variable , from-clause where-clause select-clause host-variable from-clause where-clause - see appropriate layout. - compatible data type program variable. - see appropriate layout. - see appropriate layout.

Note - need SELECT, owner, DBADM, or SYSADM Authority.


7/10/2011

<

>

DML

EXIT

selectselect-clause
The SELECT clause specifies the columns of the final result table.
SELECT ALL DISTINCT * expression

ALL DISTINCT * expression

- retains all rows of final result table (default). - eliminates duplicate rows from result table. - indicates all columns. - any expression.

7/10/2011

<

>

DML

EXIT

fromfrom-clause
The FROM clause specifies an intermediate result table. If a single table or view is identified, the intermediate result table is simply that table or view. If more than one table or view is identified, the intermediate result table consists of all possible combinations of the rows of the identified table or views. If any table or view is empty, the result is empty.
FROM table-name , view-name table-name view-name
7/10/2011

- identifies an existing table. - identifies an existing view.

<

>

DML

EXIT

wherewhere-clause
The WHERE clause specifies an intermediate result table that consists of those rows of the result table for which the search condition is true.
WHERE search-condition predicate (search-condition) predicate (search-condition)

search-condition NOT AND OR predicate AND/OR 7/10/2011

NOT

operators (=,<,>,LIKE,BETWEEN,IN,etc.) logical operators

<

>

DML

EXIT

DECLARE CURSOR
The DECLARE CURSOR statement declares a cursor and can only be embedded in an application program.
DECLARE FOR cursor-name full-select ORDER BY FOR UPDATE OF FOR FETCH ONLY OPTIMIZE FOR CURSOR WITH HOLD

7/10/2011

<

>

DML

EXIT

DECLARE CURSOR
DECLARE CURSOR (continued) cursor-name WITH HOLD full-select ORDER BY FOR UPDATE FOR FETCH OPTIMIZE FOR - name of the cursor. - cursor not closed at commit point. - select-clause, from-clause, where-clause. - orders the rows of the result table. - for positioned update. - ensure read-only - requests special optimization.

7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
8943 SELECT ORDER_STATUS_CODE , ORDER_ERROR_CD_DA , INPT_TYP_CD INTO : H , : H , : H FROM Y5SOBI0Y WHERE SRV_ORD_CNTRL_NO = : H 10279 SELECT COUNT ( * ) INTO : H FROM Y5SOBI0Y WHERE SRV_ORD_CNTRL_NO > '99000000000' AND ORDER_STATUS_CODE IN ( 'ER' , 'BT' , 'MC' , 'RD' )

7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
239 DECLARE Y5SOAR0Y-CURSOR CURSOR FOR SELECT SRV_ORD_CNTRL_NO , SEGMENT_NUMBER , TAG_ID , TAG_QUALIFIER_ID , TAG_VALUE , TAG_BYPASS_IND FROM Y5SOAR0Y WHERE ( SRV_ORD_CNTRL_NO = : H ) AND ( TAG_ID = 'RCNUM') ORDER BY TAG_VALUE

7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
577 SELECT COUNT ( * ) INTO : H FROM XIRM042Y WHERE EXISTS ( SELECT * FROM XIRM041Y WHERE SPLR_ID = : H AND USG_ID = XIRM042Y . USG_ID AND TRMSN_TMSTMP < : H AND ( INIT_ASSN_TMSTMP > : H OR EXISTS ( SELECT * FROM XIRM040Y WHERE SPLR_ID = : H AND CTN_ID = XIRM041Y . USG_ID ))) (See View Definitions on next page)
7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
CREATE VIEW CORPD000.XIRM042V AS SELECT ALL A.SPLR_ID, A.USG_ID FROM CORPD000.XY4BTB1T A, CORPD000.XY4BTB2T B WHERE A.SPLR_ID = B.SPLR_ID AND A.USG_ID = B.USG_ID CREATE VIEW CORPD000.XIRM041V AS SELECT ALL SPLR_ID, USG_ID, TRMSN_TMSTMP, INIT_ASSN_TMSTMP FROM CORPD000.XY4BTB1T CREATE VIEW CORPD000.XIRM040V AS SELECT ALL TRNSCTN_ID, TRNSCTN_SEQ_NO, SPLR_ID FROM CORPD000.XY4DSA2T
7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
297 SELECT PKST . PK_ID , PKST . TRMSN_PK_NO INTO : H , : H FROM XIRZ017Y PKST WHERE ( PKST . SPLR_ID = : H AND PKST . FIL_TYP = : H AND PKST . SPLR_LOCN_ID = : H AND PKST . BILL_ACCTG_OFC_CD = : H AND PKST . SND_ACCTG_OFC_CD = : H AND PK_ID IN (SELECT MAX ( PK_ID ) FROM XIRZ017Y WHERE SPLR_ID = : H AND FIL_TYP = : H AND SPLR_LOCN_ID = : H AND BILL_ACCTG_OFC_CD = : H AND SND_ACCTG_OFC_CD = : H ) ) (See View Definition on next page)
7/10/2011

<

>

DML

EXIT

SELECT EXAMPLES
CREATE VIEW CORPD000.XIRZ017V AS SELECT A.SPLR_ID, A.TRMSN_TMSTMP, A.TRMSN_SEQ_NO, FIL_TYP, SPLR_LOCN_ID, PK_ID, PK_SEQ_NO, PK_OBLGTN_ID, TRMSN_PK_NO, CO_NO, BILL_ACCTG_OFC_CD, SND_ACCTG_OFC_CD, INDEP_EXCH_CARR_NO, INDEP_EXCH_CARR_CD FROM CORPD000.XZ4AUA1T A, CORPD000.XZ4AUA2T B WHERE A.SPLR_ID = B.SPLR_ID AND A.TRMSN_TMSTMP = B.TRMSN_TMSTMP AND A.TRMSN_SEQ_NO = B.TRMSN_SEQ_NO AND NOT EXISTS (SELECT ERRR_CD FROM CORPD000.XY4DSA2T C WHERE C.ERRR_CD IN (SELECT D.ERRR_CD FROM CORPD000.XY4DSC6T D WHERE A.SPLR_ID = D.SPLR_ID AND D.PROG_ID = 'XIRZ5020' AND D.FUNC_ID = 'TRANSACC' ) AND B.SPLR_ID = C.SPLR_ID AND B.PK_ID = C.TRNSCTN_ID AND B.PK_SEQ_NO = C.TRNSCTN_SEQ_NO) 7/10/2011

<

DML

EXIT

DB2 Internal Functions

7/10/2011

>

MAIN MENU

EXIT

DB2 THREAD CREATION


Every DB2 program must be connected to DB2 by an attachment facility (TSO, CICS, IMS, CAF), which is the mechanism by which an environment is connected to a DB2 subsystem. Additionally, a thread must be established for each embedded SQL program that is executing. A thread is a control structure used by DB2 to communicate with an application program. The thread is used to send requests to DB2, to send data from DB2 to the program, and to communicate (through the SQLCA - SQL Communication Area) the status of each SQL Statement after it is executed. Every program must communicate with DB2 by means of a thread.

7/10/2011

>

Internal Functions

EXIT

DB2 THREAD CREATION


After the thread is established, DB2 loads the executable form of the application plan from the DB2 Directory (DSNDB01), where it is physically stored as a Skeleton Cursor Table (SKCT). The appropriate sections of each DBRM (Data Base Request Module) are loaded into an area of memory reserved for DB2 program execution called the Environmental Descriptor Management Pool (EDM Pool). All Database Descriptors (DBDs) required by the plan are also loaded into the EDM Pool.

7/10/2011

<

>

Internal Functions

EXIT

DB2 Internal Functions


Application
Application Program: Works with Columns Relational Database System: Works with Columns (Stage 2) Data Manager: Works with Rows (Stage 1) Buffer Manager: Works with Bufferpool Pages Media Manager: Works with DASD Pages
< > Internal Functions EXIT

RDS DM BM MM
7/10/2011

DASD

DB2 Internal Functions


Media Manager When a requested page is not found in the bufferpool (or Hiperpool), the Media Manager issues the I/O Request to obtain the page from DASD which it then returns to the Buffer Manager.

Buffer Manager - When an index or data page is requested by the


Data Manager, the Buffer Manager does a hash search (i.e. very fast) through the bufferpool to find the page. If it is not found, the Hiperpool is then hash searched for the requested page. If the page is in the Hiperpool, it is moved either by the Asynchronous Data Mover Facility (ADMF) or the MVS Move Page instruction. If the page is not in the Hiperpool, the Buffer Manager requests the page from the Media Manager.
7/10/2011

<

>

Internal Functions

EXIT

DB2 Internal Functions


Data Manager The Data Manager works on rows of data and acquires those rows from the Buffer Manager through the use of Stage 1 Predicates from the SQL Statement. The more rows that can be filtered out at the Data Manager level, the less overall CPU it takes to satisfy the SQL Query.

Relation Data System - Any predicates that have not been satisfied
by the Data Manager are taken care of within the Relational Data System and are referred to as Stage 2 Predicates. The Relational Data System works on specific columns (based on the SQL Statement) in preparation to passing those columns to the application program. Typically, the more Stage 2 Predicates there are, the more CPU is required to satisfy the query.
7/10/2011

<

Internal Functions

EXIT

DB2 COMMANDS & UTILITIES


COMMANDS - Bind, Rebind, Display, Free,
Start, Stop, Term Utility

DB2 Commands

UTILITIES - Copy, Load, Quiesce, Recover,


Reorg, Runstats

DB2 Utilities

7/10/2011

MAIN MENU

EXIT

BIND PLAN
The DSN subcommand BIND PLAN builds an application plan. All DB2 programs require an application plan to allocate DB2 resources and support SQL requests made during execution.
READY DSN SYSTEM (DBJO) DSN BIND PLAN(XCS02700) MEMBER(XCS02700, XCS0GONG) ACTION(REPLACE) RETAIN ISOLATION(CS) VALIDATE(BIND) ACQUIRE(USE) RELEASE(COMMIT) LIBRARY('SUB.#NM.DBRMLIB') EXPLAIN(YES)
Note - need BIND, owner, BINDADD, BINDAGENT, SYSCTRL, or SYSADM Authority.
7/10/2011

<

>

Commands

EXIT

REBIND PLAN
The DSN subcommand REBIND PLAN rebinds an application plan when changes have been made affect the plan, but the SQL statements in the programs have not changed (ex. a new index has been added or Runstats has been run). REBIND PLAN is generally faster than BIND PLAN but if any SQL statements have been changed or if a program is recompiled, use BIND PLAN with the ACTION(REPLACE) keyword.

7/10/2011

<

>

Commands

EXIT

REBIND PLAN
READY DSN SYSTEM (DBJO) DSN REBIND PLAN(XCS02700) ISOLATION(CS) VALIDATE(BIND) ACQUIRE(USE) RELEASE(COMMIT) EXPLAIN(YES)

* * * * *

* - Default is the value last time the plan was bound. Note - need BIND, owner, BINDAGENT, SYSCTRL, or SYSADM Authority.

7/10/2011

<

>

Commands

EXIT

BIND PACKAGE
The DSN subcommand BIND PACKAGE builds an application package. For DB2 the description of the package is recorded in the catalog and a prepared package is saved in the directory.

7/10/2011

<

>

Commands

EXIT

BIND PACKAGE
READY DSN SYSTEM (DBJO) DSN BIND PACKAGE(location-name.collection-id) OWNER(auth-id)/QUALIFIER(qualifier-name) MEMBER(member-name) LIBRARY(lib-name) ACTION(REPLACE/ADD VALIDATE(RUN/BIND) ISOLATION(RR/CS) RELEASE(COMMIT/DEALLOCATE) EXPLAIN(NO/YES) CURRENTDATA(NO/YES) ACQUIRE(USE) - required for packages
Note - need BIND, owner, BINDADD, BINDAGENT, PACKADM, SYSCTRL, or SYSADM.
7/10/2011

<

>

Commands

EXIT

REBIND PACKAGE
The DSN subcommand REBIND PACKAGE rebinds an application package when changes have been made that affect the package, but the SQL statements in the program have not changed (ex. a new index is added or Runstats was run). REBIND PACKAGE is generally faster than BIND PACKAGE but if the SQL statements have changed or the program has been recompiled, use BIND PACKAGE with the ACTION(REPLACE) parameter.

7/10/2011

<

>

Commands

EXIT

REBIND PACKAGE
READY DSN SYSTEM (DBJO) DSN REBIND PACKAGE(location-name.collection-id) OWNER(auth-id)/QUALIFIER(qualifier-name) MEMBER(member-name) LIBRARY(lib-name) VALIDATE(RUN/BIND) ISOLATION(RR/CS) RELEASE(COMMIT/DEALLOCATE) EXPLAIN(NO/YES) * - Default is the value last time the package was bound.
Note - need BIND, owner, BINDAGENT, PACKADM, SYSCTRL, or SYSADM Authority.
7/10/2011

* * * *

<

>

Commands

EXIT

DISPLAY DATABASE
The DB2 DISPLAY DATABASE command displays information about the status of DB2 databases, tablespaces, tables, indexes, and partitions.
DISPLAY DATABASE (database-name ,) * name1:name2 name* SPACENAM (space-name ,) USE LOCK * name1:name2 name* CLAIMERS AFTER LIMIT (50) ACTIVE * int RESTRICT
< > Commands EXIT

7/10/2011

DISPLAY DATABASE
DISPLAY DATABASE (continued) database-name name1:nam2 name* USE LOCKS CLAIMERS AFTER LIMIT ACTIVE int RESTRICT - name of at least one database (or *). - range of database/space names. - partial name of database/space. - correlation-id, connection-id, auth-id. - transaction locks for tables and indexes. - claims on tables and indexes. - collates after a database/space name. - limits the number displayed. - displays allocated spaces. - integer value 50 or less. - limits spaces to those in restricted mode.

7/10/2011

Note - need DISPLAY, DISPLAYDB, DBMAINT, DBCTRL, DBADM, SYSOPR, SYSCTRL, or SYSADM Authority. < > Commands EXIT

DISPLAY DATABASE EXAMPLE


-DIS DB(UCBSO02Q) SPACENAM(UCBSO02S)
DSNT360I - *************************************************** DSNT361I - * DISPLAY DATABASE SUMMARY * GLOBAL DSNT360I - *************************************************** DSNT362I - DATABASE = UCBSO02Q STATUS = RW DBD LENGTH = 32294 DSNT397I NAME TYPE PART STATUS -------- ---- ---- ------------------ -------- -------- -----UCBSO02S TS RW ******* DISPLAY OF DATABASE UCBSO02Q ENDED ************** DSN9022I - DSNTDDIS 'DISPLAY DATABASE' NORMAL COMPLETION

7/10/2011

<

>

Commands

EXIT

DISPLAY DATABASE EXAMPLE


-DIS DB(XXDJC00D) SPACENAM(*) RESTRICT
DSNT360I - *************************************************** DSNT361I - * DISPLAY DATABASE SUMMARY * RESTRICTED DSNT360I - *************************************************** DSNT362I - DATABASE = XXDJC00D STATUS = RW DBD LENGTH = 12104 DSNT397I NAME TYPE PART STATUS -------- ---- ---- ------------------ -------- -------- -----XXDJCBSS TS RW,COPY XXDJCFTS TS RW,COPY XXDJCJPS TS RW,COPY XXDJCRES TS RW,COPY ******* DISPLAY OF DATABASE XXDJC00D ENDED *************** DSN9022I - DSNTDDIS 'DISPLAY DATABASE' NORMAL COMPLETION 7/10/2011

<

>

Commands

EXIT

DISPLAY THREAD
The DB2 DISPLAY THREAD command displays current status information about DB2 threads. A DB2 thread is either an allied thread or a database access thread and is active, inactive, or indoubt. Distributed threads have a connection with a remote location (active or inactive) or had a connection with a remote location (indoubt). An allied thread may or may not be distributed but a database access thread (DBAT) is always distributed.

7/10/2011

<

>

Commands

EXIT

DISPLAY THREAD
DISPLAY THREAD (connection-name ,) * TYPE (ACTIVE) INDOUBT INACTIVE * LOCATION (location-name ,) DETAIL * LUWID (luwid) token

7/10/2011

<

>

Commands

EXIT

DISPLAY THREAD
DISPLAY THREAD (continued) connection-name TYPE - one or more connection names (or *) - ACTIVE - only active threads. - INDOUBT - two-phase commit. - INACTIVE - only inactive threads. -* - all threads. - limits display to distributed threads. - specific distributed location ( or *) - fully qualified LUnetwork name - up to 5 digit decimal id for luwid - additional conversation activity info.

LOCATION location-name LUWID token DETAIL

Note - need DISPLAY, SYSOPR, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Commands

EXIT

DISPLAY THREAD EXAMPLE


-DIS THREAD(*)
DSNV401I - DISPLAY THREAD REPORT FOLLOWS DSNV402I - ACTIVE THREADS NAME ST A REQ ID AUTHID PLAN ASID DB2CALL T 63 DBJBGATE SRUO G4DB2PLN 002C DB2CALL T 28118 DBJBMGR DBJBMGR 0055 #RB N 0 0159 #RB N 2 IMSRBCTL 0114 #RG N 1574 0009XCF06000 KPURCEL 0138 #RG N 637 0006XBF0EF00 CMATHIA 00AF #RG N 2 IMSRGCTL 0154 #RH N 164 0001XBF0QX00 MMANNA 0097 #RH N 32 0009XCF00200 IN1800AD 00B5 #RH N 2 IMSRHCTL 00B2 TSO TR 55 MKENT MKENT PEBR 009D V444-USWDEN.DD019.AC4072837B3C=8631 ACCESSING DATA AT V446-DBJN DBJM TSO T * 3 MWINGFI MWINGFI 0151 TSO T 5 BXGOMEZ BXGOMEZ PEBR 015A BATCH N 1 MROJAK 009F DISPLAY ACTIVE REPORT COMPLETE DSN9022I - DSNVDT '-DIS THREAD' NORMAL COMPLETION

7/10/2011

<

>

Commands

EXIT

DISPLAY UTILITY
The DB2 DISPLAY UTILITY command displays the status of utility jobs. A job can be active, stopped, or terminating. One set of messages is returned for each job identified by the command.
DISPLAY UTILITY (utility-id) partial-id* *

utility-id - identifies a single utility job by its UID parameter. partial-id* - identifies a set of utility jobs. * - all utility jobs. Note - need DISPLAY, SYSOPR, SYSCTRL, or SYSADM Authority.
7/10/2011

<

>

Commands

EXIT

DISPLAY UTILITY EXAMPLE


-DIS UTIL(*)
DSNU100I - DSNUGDIS - USERID = USWC125 UTILID = LOADSMF PROCESSING UTILITY STATEMENT 10 UTILITY = LOAD PHASE = BUILD COUNT = 0 STATUS = STOPPED DSNU100I - DSNUGDIS - USERID = JCASTIN UTILID = JCASTIN.X4DRA4LD PROCESSING UTILITY STATEMENT 1 UTILITY = LOAD PHASE = BUILD COUNT = 0 -DIS UTIL(*)STATUS = STOPPED DSN9022I - DSNUGCCC '-DIS UTIL' NORMAL COMPLETION

7/10/2011

<

>

Commands

EXIT

FREE PACKAGE
The DSN FREE PACKAGE subcommand can be used to delete a specific version of a package, all versions, or whole collections of packages. It deletes corresponding table entries from the SYSIBM.SYSPACKAGES catalog tables. Authorization for a package name is only removed when all versions of a package are deleted. This subcommand does not proceed until all currently executing applications using the package finish executing.
FREE PACKAGE location-name collection-id package-id version-id * location-name.collection-id.package-id.version-id * * * - location of the DBMS. - name of the collection of packages. - specific package to be deleted. - specific version of the package. - indicates all (better not).

Note - need BINDAGENT, SYSCTRL, SYSADM Authority.


7/10/2011

<

>

Commands

EXIT

FREE PACKAGE EXAMPLE


FREE PACKAGE dbjr.tollcol1.* Frees all packages within collection (tollcol1) on COTHOR.

FREE PACKAGE dbjm.xirdc00c.xirm1000.* Frees all versions of package (xirm1000) in collection (xirdc00c) on COACCT.

7/10/2011

<

>

Commands

EXIT

FREE PLAN
The DSN FREE PLAN subcommand deletes application plans from DB2. It deletes corresponding table entries from the SYSIBM.SYSPLANS catalog tables. All authorization for an application plan name is dropped. This subcommand does not proceed until all currently executing applications using the package finish executing.
FREE PLAN (plan-name ,) * plan-name - lists the names of one or more plans to delete. * - indicates all (don't even think about it). Note - need BIND, BINDAGENT, SYSCTRL, or SYSADM Authority.
7/10/2011

<

>

Commands

EXIT

FREE PLAN EXAMPLE

FREE PLAN (XIRB1000, XIRB2000) Frees plans XIRB1000 and XIRB2000 and angers RIB.

7/10/2011

<

>

Commands

EXIT

START DATABASE
The DB2 START DATABASE command is typically used after a previous STOP DATABASE command or after a tablespace or index has been placed in deferred restart status by DB2. It makes the specified database available for use. Depending on the options specified, a database can be started read-only, read-write (normal) or utility-only.
START DATABASE (database-name ,) * (database-name) SPACENAM(space-name ,) * PART(integer ,) ACCESS(RW) RO UT FORCE
7/10/2011

<

>

Commands

EXIT

START DATABASE
START DATABASE (continued) database-name space-name integer RW RO UT FORCE - name of the database. - name of tablespace or indexspace. - partition number - Read/Write (normal default) - Read Only - Utility - Resets all flags so be cautious.

Note - need STARTDB, DBMAINT, DBCTRL, DBADM, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Commands

EXIT

STOP DATABASE
The DB2 STOP DATABASE command makes the specified database unavailable for applications and closes the datasets. Tablespaces and indexes that are explicitly stopped with this command must be explicitly started with the START DATABASE command.
STOP DATABASE (database-name ,) * (database-name) SPACENAM(space-name ,) * PART(integer ,) AT(COMMIT)
7/10/2011

<

>

Commands

EXIT

STOP DATABASE
STOP DATABASE (continued) database-name space-name integer COMMIT - name of the database. - name of tablespace or indexspace. - partition number - allows STOP command at commit.

Note - need STOPDB, DBMAINT, DBCTRL, DBADM, SYSCTRL, or SYSADM Authority.

7/10/2011

<

>

Commands

EXIT

TERM UTILITY
The DB2 TERM UTILITY command terminates execution of a utility job step and releases all resources associated with the step. When executing, a utility will not terminate until it checks to see if a TERM UTILITY was issued. This check is done periodically from active utilities.
TERM UTILITY (utility-id) partial-id* * utility-id - identifies a single utility job by its UID parameter. partial-id* - identifies a set of utility jobs to terminate. * - all utility jobs (think again). Note - need SYSOPR, SYSCTRL, SYSADM Authority or originator.
7/10/2011

<

Commands

EXIT

IMAGE COPY UTILITY


The COPY online utility creates up to four image copies of a tablespace or a dataset within a tablespace. The Full Image Copy is a copy of all pages in a tablespace or dataset. The Incremental Image Copy is a copy only of pages modified since the last use of the COPY utility.
COPY TABLESPACE database-name. tablespace-name

DSNUM ALL COPYDDN SYSCOPY integer RECOVERYDDN(ddname) FULL YES NO


7/10/2011

SHRLEVEL REFERENCE CHANGE


> Utilities EXIT

IMAGE COPY UTILITY


IMAGE COPY UTILITY (continued) tablespace-name ALL integer SYSCOPY ddname YES NO REFERENCE CHANGE - name of tablespace to be copied. - entire tablespace. - partition number. - cataloged primary copy. - recovery site DD name. - full image copy (default). - incremental image copy. - allows read-only access (default). - allows updates.

Note - need IMAGCOPY, DBADM, DBCTRL, DBMAINT, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Utilities

EXIT

LOAD UTILITY
The LOAD online utility loads data into one or more tables in a tablespace, or one or more partitions of a tablespace, and can replace or append the existing data in either case. The LOAD DATA statement describes the data to be loaded and provides resource allocation data.
LOAD DATA INDDN SYSREC ddname REPLACE KEEPDICTIONARY WORKDDN (SYSUT1,SORTOUT) ddname1,ddname2

RESUME NO RESUME YES LOG YES NO

. . SORTDEVT device-type INTO TABLE table-name 7/10/2011

SORTNUM integer

<

>

Utilities

EXIT

LOAD UTILITY
LOAD UTILITY (continued) SYSREC RESUME NO RESUME YES KEEPDICT... REPLACE LOG YES LOG NO SYSUT1 SORTOUT device-type integer - input record format. - loads into an empty table. - loads into a non-empty table at end. - retains compression dictionary. - replaces all existing rows on table. - all records loaded are logged. - no logging - copy pending flag set. - default sort input. - default sort output. - DFSORT dynamic allocation. - number of temporary datasets.

Note - need LOAD, DBADM, DBCTRL, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Utilities

EXIT

QUIESCE UTILITY
The QUIESCE utility establishes a consistency point (current log RBA) for a tablespace, partition, or list of tablespaces then records it in the SYSIBM.SYSCOPY catalog table.
QUIESCE TABLESPACE database-name.tablespace-name PART integer WRITE YES NO - name of the database (optional). - name of the tablespace to be quiesced. - partition number. - externalize changed pages to DASD. - don't externalize at transaction consistency.

database-name tablespace-name integer WRITE YES WRITE NO

Note - need IMAGCOPY, DBADM, DBCTRL, DBMAINT, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Utilities

EXIT

RECOVER INDEX UTILITY


The RECOVER INDEX recreates indexes from the referenced table.
RECOVER INDEX (index-name ALL PART integer ,)

TABLESPACE database-name.tablespace-name PART integer WORKDDN(SYSUT1) ddname SORTDEVT device-type SORTNUM integer

7/10/2011

<

>

Utilities

EXIT

RECOVER INDEX UTILITY


RECOVER INDEX UTILITY (continued) index-name ALL PART integer database-name tablespace-name SYSUT1 ddname device-type SORTNUM - name of the index to be recovered - recover all defined indexes. - physical partition of partitioned index. - name of the database. - name of the tablespace to be recovered. - default temporary work file. - DD name for the temporary work file. - device type (i.e. DASD) of temporary datasets. - number of temporary datasets.

Note - need RECOVERDB, DBADM, DBCTRL, SYSCTRL, or SYSADM.


7/10/2011

<

>

Utilities

EXIT

RECOVER TABLESPACE UTILITY


The RECOVER TABLESPACE utility recovers an entire tablespace, a dataset, pages within an error range, or a single page. The data is recovered from image copies of a tablespace and the database log change records. It does not recover indexes.
RECOVER TABLESPACE database-name.tablespace-name DSNUM ALL integer TORBA x'byte-string' TOCOPY dataset-name
7/10/2011

LOGONLY

<

>

Utilities

EXIT

RECOVER TABLESPACE UTILITY


RECOVER TABLESPACE UTILITY (continued) database-name tablespace-name ALL integer x'byte-string' LOGONLY dataset-name - name of the database. - name of the tablespace to be recovered. - recovers entire tablespace (default). - number of the partition. - HEX Relative Byte Address from the log. - applies on log records to the dataset. - MVS generation dataset (fully qualified).

Note - need RECOVERDB, DBADM, DBCTRL, SYSCTRL, or SYSADM.


7/10/2011

<

>

Utilities

EXIT

REORG TABLESPACE UTILITY


The REORG TABLESPACE utility reorganizes a tablespace or a partition improve access performance and reclaim fragmented space.
REORG TABLESPACE database-name.tablespace-name LOG YES NO SORTDATA KEEPDICTIONARY

PART integer UNLDDN SYSREC ddname WORKDDN(SYSUT1 ddname1 ,SORTOUT) ,ddname2

SORTDEVT device-type SORTNUM integer1


7/10/2011

<

>

Utilities

EXIT

REORG TABLESPACE UTILITY


REORG TABLESPACE UTILITY (continued) tablespace-name LOG YES LOG NO SORTDATA KEEP... PART integer SYSREC ddname WORKDDN - name of the tablespace to be reorganized. - logs records during the reload phase (default). - no logging (turns on copy pending). - sort in clustering order. - retains existing compression dictionary. - partition to be reorganized. - default unload dataset. - DD name of the unload dataset. - intermediate temporary dataset.

Note - need REORG, DBADM, DBCTRL, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Utilities

EXIT

REORG INDEX UTILITY


The REORG INDEX utility reorganizes an index or index partition to improve access performance and reclaim fragmented space.
REORG INDEX index-name

PART integer UNLDDN SYSREC ddname WORKDDN(SYSUT1 ddname1 SORTDEVT device-type ,SORTOUT) ,ddname2 SORTNUM integer1

7/10/2011

<

>

Utilities

EXIT

REORG INDEX UTILITY


REORG INDEX UTILITY (continued) index-name PART integer SYSREC ddname WORKDDN SYSUT1 SORTOUT ddname1 ddname2 device-type integer1 - name of the index to be reorganized. - partition to be reorganized. - default unload dataset. - DD name of the unload dataset. - intermediate temporary dataset. - default sort input temporary dataset. - default sort output temporary dataset. - sort input temporary dataset. - sort output temporary dataset. - DFSORT device type (i.e. DASD). - number of temporary sort datasets.

Note - need REORG, DBADM, DBCTRL, SYSCTRL, or SYSADM Authority.


7/10/2011

<

>

Utilities

EXIT

RUNSTATS TABLESPACE UTILITY


The RUNSTATS utility gathers summary information about the characteristics of the data in tablespaces, indexes, and partitions which is recorded in the DB2 Catalog and subsequently utilized by DB2 to select access paths during the BIND process.
RUNSTATS TABLESPACE dbname.tsname PART integer TABLE ALL (table-name)

COLUMN ALL (col-name

,)

INDEX (ALL) SRHLEVEL REFERENCE (ixname PART int ,) CHANGE REPORT NO YES
7/10/2011

UPDATE ALL ACCESSPATH < > Utilities EXIT

RUNSTATS TABLESPACE UTILITY


RUNSTATS TABLESPACE UTILITY (continued) dbname.tsname PART integer TABLE ALL table-name COLUMN ALL col-name INDEX (ALL) ixname PART int REFERENCE CHANGE REPORT
7/10/2011

- database and tablespace name. - specific partition for runstats. - all columns of all tables in tablespace. - specific table name. - all columns within a specific table. - specific column names. - all defined indexes. - specific index names. - specific index partition. - allows read-only access by other programs. - allows update access by other programs. - NO (updates) YES (no catalog updates).

Note - need STATS, DBADM, DBCTRL, DBMAINT, SYSCTRL, or SYSADM.


< > Utilities EXIT

RUNSTATS TABLESPACE UTILITY


RUNSTATS TABLESPACE UTILITY (continued) dbname.tsname PART integer TABLE ALL table-name COLUMN ALL col-name INDEX (ALL) ixname PART int REFERENCE CHANGE REPORT
7/10/2011

- database and tablespace name. - specific partition for runstats. - all columns of all tables in tablespace. - specific table name. - all columns within a specific table. - specific column names. - all defined indexes. - specific index names. - specific index partition. - allows read-only access by other programs. - allows update access by other programs. - NO (updates) YES (no catalog updates).

Note - need STATS, DBADM, DBCTRL, DBMAINT, SYSCTRL, or SYSADM.


< > Utilities EXIT

RUNSTATS INDEX UTILITY


The RUNSTATS INDEX utility gathers summary information on indexes.
RUNSTATS INDEX ( index-name PART integer ,) (ALL ) TABLESPACE dbname.tsname SRHLEVEL REFERENCE CHANGE REPORT NO YES UPDATE ALL ACCESSPATH SPACE NONE
> Utilities EXIT

7/10/2011

<

RUNSTATS INDEX UTILITY


RUNSTATS INDEX UTILITY (continued) index-name PART integer ALL dbname.tsname PART integer REFERENCE CHANGE REPORT UPDATE ALL ACCESSPATH SPACE NONE
7/10/2011

- specific index name. - specific partitioned index. - all indexes within the tablespace. - database and tablespace name. - specific partition for runstats. - allows read-only access by other programs. - allows update access by other programs. - NO (updates) YES (no catalog updates). - all collected statistics updated in catalog. - updates access path-related info only. - updates space-related info only. - no updates (used with REPORT YES).

Note - need STATS, DBADM, DBCTRL, DBMAINT, SYSCTRL, or SYSADM.


< Utilities EXIT

Appendixes
Prefetch Definitions DB2 Data Types DB2 Limits DB2 Online Manuals DB2 Reference Books
Prefetch Data Types DB2 Limits Online Manuals Reference Books

7/10/2011

<

>

MAIN MENU

EXIT

PREFETCH
SEQUENTIAL - DB2 issues an I/O for the next 32 4K pages in the tablespace or index if the associated bufferpool has at least 1000 pages. Utilities can get up to 64 4K pages. The DB2 Explain will indicate sequential prefetch with an 'S' in the Prefetch Column. LIST - DB2 checks to see how many of the requested pages for the qualifying rows are identical; then eliminates these duplicates before issuing the multiple I/Os. The DB2 Explain will indicate list prefetch with an L' in the Prefetch Column. DYNAMIC - This is also referred to as Sequential Detection. If neither sequential or list prefetch is turned on, DB2 will keep track of the previous 8 ]/Os and if at least 5 of those I/Os are considered4sequential, DB2 will issue an I/O for the next 32 HK pages of the index or tablespace. DB2 will also disable dynamic prefetch if less than 5 of the last 8 I/Os are considered sequential or a COMMIT is issued.
7/10/2011

<

>

Appendixes

EXIT

DB2 Data Types


Data Type
SMALLINT INTEGER REAL FLOAT(1..21) DOUBLE PRECISION FLOAT(22..53) DECIMAL(m,n) CHARACTER(n) VARCHAR(n)

Size
2 bytes 4 bytes 4 bytes 4 bytes 8 bytes 8 bytes (m/2)+1 bytes n bytes 2 to n+2 bytes

Value Range
+ 32,767 + 2,147,483,647 5.4 x 10-79 to 7.2 x 1075 5.4 x 10-79 to 7.2 x 1075 5.4 x 10-79 to 7.2 x 1075 5.4 x 10-79 to 7.2 x 1075 1-1031 to 1031-1 max. 254 characters max. 4,046 bytes 32,704 for 32K page

COBOL Picture
PIC S9(4) COMP PIC S9(9) COMP PIC USAGE COMP 1 PIC USAGE COMP 1 PIC USAGE COMP 2 PIC USAGE COMP 2 PIC S9(m-n)V9(n) COMP 3 PIC X(n) 01 VARCHAR. 49 LTH PIC S9(4) COMP. 49 COLUMN PIC X(n). PIC G(n) DISPLAY 1 01 VARCHAR. 49 LTH PIC S9(4) 49 COLUMN PIC G(n) PIC X(10) PIC X(8) PIC X(26)

GRAPHIC(n) VARGRAPHIC(n)

2n bytes max. 127 chars. 2 to 2n+2 bytes max. 2,023 chars.

DATE TIME TIMESTAMP 7/10/2011

4 bytes 3 bytes 10 bytes

0001-01-01 to 9999-12-31 00.00.00 to 24.00.00 0001-01-01.00.00.00.000000 to 9999-12-31.24.00.00.000000

<

>

Appendixes

EXIT

DB2 Limits
Stogroup name Volumes per Stogroup Database name Max no. of databases Authorization ID Partitions per tablespace (non-LARGE) (LARGE) Partition size (non-LARGE) 1- 16 parts 17 - 32 parts 33 - 64 parts Partition size (LARGE) 1 - 254 parts Segment size Tablespace size
7/10/2011

8 bytes 133 8 bytes 65,279 8 bytes 64 254 4 Gigabytes 2 Gigabytes 1 Gigabytes 4 Gigabytes 64 pages 1,016 Gigabytes > Appendixes EXIT

<

DB2 Limits
Table name View name Alias name Synonym name Column name Cursor name Host identifier No. base tables per view Max. columns per table/view Index name Columns per index Index columns size (Partitioned) (non-Partitioned) 18 bytes 18 bytes 18 bytes 18 bytes 18 bytes 18 bytes 64 bytes 15 750 18 bytes 64 40 bytes 254 bytes

7/10/2011

<

>

Appendixes

EXIT

DB2 Limits
Plan name Package name Collection name Version name DBRM name Correlation ID Max. row length Max. rows per page Max. index levels Largest SQL statement Predicates per WHERE clause Predicates per HAVING clause Concurrent users Open datasets 8 bytes 8 bytes 18 bytes 64 bytes 8 bytes 18 bytes 4056 bytes 127 or 255 comp. 6 32,765 bytes 300 300 2,000 10,000

7/10/2011

<

>

Appendixes

EXIT

DB2 Online Manuals


The DB2 Version 5.1 Manuals are located on the Fourth Platforms server in Bellevue: itsblvf03\omega
(P_ivp\06_ComDocs\04_Software\04_Reference_Guides\DB2 Manuals\DB2 V5.1)

The Manuals are in PDF format and require Adobe Acrobat Reader 3.0 or later. The DB2 V5.1 folder contains the following manuals: Application Programming & SQL Guide Administration Guide Command Guide Utility Guide & Reference SQL Reference Messages & Codes
7/10/2011

<

>

Appendixes

EXIT

DB2 Reference Books


DB2 Developers Guide (Third Edition) by Craig Mullins -1997 DB2 for OS/390 Development for Performance by Gabrielle Wiorkowski - 1998 DB2 For The COBOL Programmer Version 4.1 (Vol. 1) by Curtis Garvin, Steve Eckols - 1999

7/10/2011

<

>

Appendixes

EXIT

You might also like