MF DB2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

DB2

===
Pre Compile
----------
1. Expand (copied) INCLUDE members.
2. does a very basic syntax check to make sure that the column and table names are valid (that
they're spelled correctly and that the columns and the table exist). Check against DCLGEN, there is
no connection to DB2.
3. DB2 Precompiler is to split the program into two parts: a COBOL and a DB2 part.

Bind
-----
1. The first of the BIND tasks is an authorization check.
2. The second BIND task is a bit redundant. BIND, like precompile, must also check the syntax of the
SQL, but the BIND check is more sophisticated. Instead of using the top, DECLARE TABLE portion of
the DCLGEN, BIND uses the DB2 CATALOGtable information to make sure that the column names are
valid, that comparisons are numeric-to-numeric, and so on.
3. After all that input (and more) is weighed and compared, the cheapest, most cost effective access
path is chosen, and the runtime instructions for that one path are created.

BIND PARAMETERS
---------------
MEMBER - In bind package,
LIRARY - DBRM library name ,
ACTION(add/replace)- package or plan can be add or replace.
ISOLATION - Determines the duration of the page lock.
AQUIRE - Lock a table on use
RELEASE - releases when the plan terminates
VALIDATE - It will be check about authorization.
EXPLAIN - loads the access path selected by the optimizer in table
OWNER - That is the table creator name, which specifies the table needs to be accessed is dev,UAT
or Prod

SQLCODE
-------
SQLCODE -180 SQLSTATE 22007
Bad data in Date/Time/Timestamp
String representation of DATE, TIME, TIMESTAMP is invalid
SQLCODE -181 SQLSTATE 22007
Bad data in Date/Time/Timestamp
Value for DATE, TIME, TIMESTAMP is invalid
SQLCODE -305 Null indicator needed
‘-1’ : Field is having NULL value

‘ 0’ : Field is Not NULL value

‘-2’ : Field value is truncated

SQLCODE -501 Cursor not open on FETCH


SQLCODE -502 Opening cursor that is already open
SQLCODE -530 SQLSTATE 23503
Referential integrity prevents the INSERT/UPDATE
SQLCODE -532 SQLSTATE 23504
Referential integrity (DELETE RESTRICT rule) prevents the DELETE
SQLCODE -803 SQLSTATE 23505
Duplicate key on insert or update
SQLCODE -805
DBRM or package not found in plan
Is plan name correct?
SQLCODE -811 More than one row retrieved in SELECT INTO
SQLCODE -818 Plan and program: timestamp mismatch
SQLCODE -904 SQLSTATE 57011
Unavailable resource. Someone is locking the data you need
SQLCODE -911 SQLSTATE 40000
Deadlock or timeout. Rollback has been done.
SQLCODE -922 Authorization needed

CURSOR
-------
DECLARE C_NAME CURSOR FOR SELECT -------
DECLARE C_NAME CURSOR FOR SELECT ------- FOR UPDATE OF TABLE --> Updatable cursor
(UPDATE WHERE CURRENT OF C_NAME)

WITH HOLD-Does not close after commit/ Closes if close cursor stmt, appl'n prog terminate
(DECLARE CURSOR C_NAME CURSOR WITH HOLD FOR SELECT -------

SCROLLABLE-

ROWSET POSITIONING-
Def'n--DECLARE C_NAME CURSOR WITH ROWSET POSITIONING FOR SELECT-----
Fetch--FETCH NEXT ROESET FROM C_NAME FOR 20 ROWS INTO WS1 , WS2 ----
Need to define a variable array and need to code a fetch loop.

In open statement cursor present at first row of the result set to be processed.
SQLERRD(3)--No of rows fetched.

Alias
-----
1. Pointer to cursor.
2. substitute to 3 part name of table.
3. if table dropped, alias doesn't drop.

Synonym
-------
1. To refer table in diff name.
2. Pvt ptr.
3. If table dropped, Synonym drops

View
----
1. Alternate way of viewing data in one or more table.
2. Not physical object n doesn't store actual data.

Isolation Level
---------------
CS (Cursor Stability) Default isolation level: Hold a lock on the row or page only if the cursor is
pos'ned on that page or row. Lock is released when cursor move to new row or page, but held until
commit issued.During the lock no other appl'n can do any DB opr'n apart from SELECT.

RS (Read Stability): Lock the entire result set of the query.During the lock no other appl'n can do any
DB opr'n apart from SELECT.

UR (Uncommitted Read): Don't take any lock and ignore other lock. Allow read access to locked data.

RR (Repeatable Read): Hold lock on all rows since last commit point. Most restrictive.

COPY PENDING
------------
A state in which, an Image Copy on a table needs to be taken, In this status, the table is available
only for queries. You cannot update this table. To remove the COPY PENDING status, you take an
image copy or use REPAIR utility.

CHECK PENDING
-------------
When a table is LOADed with ENFORCE NO option, then the table is left in CHECK PENDING status. It
means that the LOAD utility did not perform constraint checking.

FOREIGN KEY DEFINITION


----------------------
CREATE TABLE DEPARTMENT
(DEPTNO CHAR(3) NOT NULL,
DEPTNAME VARCHAR(29) NOT NULL,
MGRNO CHAR(6),
ADMRDEPT CHAR(3) NOT NULL,
LOCATION CHAR(16),
PRIMARY KEY (DEPTNO))
IN RESOURCE

The statement defining the dependent table, EMPLOYEE, is:


CREATE TABLE EMPLOYEE
(EMPNO CHAR(6) NOT NULL PRIMARY KEY,
FIRSTNME VARCHAR(12) NOT NULL,
LASTNAME VARCHAR(15) NOT NULL,
WORKDEPT CHAR(3),
PHONENO CHAR(4),
PHOTO BLOB(10m) NOT NULL,
FOREIGN KEY DEPT (WORKDEPT)
REFERENCES DEPARTMENT ON DELETE NO ACTION)
IN RESOURCE

DELETE RULE
-----------
On delete set NULL
On delete cascade delete
On delete No action

RUNSTAT
-------
Update the statistics of the table in system cataloge tables. (no of records, no of pages etc)

REORG
-----
Organise the table on clustered index. so that system can access records easily. Needed when index
column updated.

Load Utility
------------
Term Utility(EXEC DB2TSOB)
===========
DSN SYSTEM(DT11)
-TERM UTILITY(SRFPRCE)
END

Stop DB(EXEC DB2TSOB)


=======
-STO DATABASE(S148) SPACENAM(SRFCTRT)
-STO DATABASE(S148) SPACENAM(SRFCTRT1)

Start DB(EXEC DB2TSOB)


========
DSN SYSTEM(DT11)
-START DATABASE(S148) SPACENAM(SRFPRCE) ACCESS(UT)
-START DATABASE(S148) SPACENAM(SRFPRCE1) ACCESS(UT)
END

Load data into table (EXEC DSNUPROC)


====================
LOAD DATA RESUME YES LOG NO NOCOPYPEND
INTO TABLE S.SRFPRCE
(
C_SC_FAM POSITION( 1 )
CHAR( 10) ,
)
Start DB(EXEC DB2TSOB)
========
DSN SYSTEM(DT11)
-START DATABASE(S148) SPACENAM(SRFPRCE) ACCESS(RW)
-START DATABASE(S148) SPACENAM(SRFPRCE1) ACCESS(RW)
END

SQL
=====
1. The UNION operator selects only distinct values by default. To allow duplicate values, use the ALL
keyword with UNION.i.e. UNION ALL

You might also like