Schema Purpose
SYSTABLES SYSIBM Information about all tables in the database
SYSINDEXES SYSIBM Information about the indexes on all tables
SYSVIEWS SYSIBM Information on all views in the database
select name, creator
from sysibm.systables
where creator = 'FUZZY'

Data Definition Language (​

Create, Alter and Drop 
Data Manipulation Language (​

Select, Insert, Update and Delete 
 Data Control Language (​

Grant and  Revoke 
All the tables are created in table spaces. 
Table spaces reside on ESDS or LDS 
Creation of temporary tables: 
1) ​
*********** IMP ********* the temporary table is created only when when some SQL 
operation is done on it like( select,update) 
4)  one more way to create a temporary table is to use the command ​
declare global temporary 
table ​
name, for this a temporary DB and temporary TS have to be created as follows: 
The second kind of temporary table exists only until the session exists 
Handling NULL values: 
It is a logical derivation of a table from other table/tables. A View does not exist in its own 

They provide a certain amount if logical independence 
They allow the same data to be seen by different users in different ways 
In DB2 a view that is to accept a update must be derived from a single base table 
Mean ‘another name’ for the table. 
Aliases are used basically for accessing remote tables (in distributed data processing), which 
add a location prefix to their names. 
Using aliases creates a shorter name. 
Also means another name for the table, but is private to the user who created it. 
    CREATE VIEW <Viewname> (<columns>) 
                      AS Subquery  (Subquery ­ SELECT FROM                    other Table(s)) 
    CREATE ALIAS <Aliasname> FOR <Tablename> 
    CREATE SYNONYM <Synonymname> FOR <Tablename> 
FROM IBMGRP.MEMBERDETAILS;                            
******* When a VIEW is updated the table is also updated ******* 
Embedded SQL 
It is like the file I/O 
Normally the embedded SQL statements contain the host variables coded with the INTO clause 
of the SELECT statement. 
They are delimited with EXEC SQL ...... END EXEC. 
SELECT Empno, Empname ​ ​
INTO :H­empno, :H­empname 
    WHERE empno = 1001 

Used when a large number of rows are to be Selected 
Can be likened to a pointer 
Can be used for modifying data using ‘FOR UPDATE OF’ clause 

 :Job  END­EXEC.The four (4) Cursor control statements are ­  •​ Declare​  :  name assigned for a particular SQL statement  •​ Open​  :  readies the cursor for row retrieval; sometimes builds the result table. :Empname.  :Dept.      When you update a row or delete a row from table using cursor.             CLOSE  E.Dept. UPDATE  E.g. However it does  not assign values to the host variables  •​ Fetch​  : returns data from the results table one row at a time and assigns the value to specified  host variables  •​ Close​  : releases all resources used by the cursor    DECLARE​ :  EXEC SQL                                DECLARE EMPCUR CURSOR FOR        SELECT  Empno. Empname. ­ For the Close statement  EXEC SQL        CLOSE EMPCUR  END EXEC.g. Data integrity is maintained because the current row is locked for usage. ­ For the Update statement using cursors  .         OPEN: EXEC SQL       OPEN EMPCUR  END­EXEC.      FETCH: EXEC SQL       FETCH EMPCUR       INTO :Empno. Job                         FROM EMP                  WHERE Dept = 'D11'  FOR UPDATE OF Job             ​ END­EXEC.

e  DSNELI)    Coding SQL in COBOL:    Declaring TABLE/VIEWS is COBOL program is not mandatory but it helps  documentation.        Program preparation: PRECOMPILE​ ---> separates all the DB2 code and writes it in a DBRM and Modified source code and DBRM are tagged with •​ Searches all the SQL statements and DB2 related INCLUDE members and comments out every  SQL statement in the program  •​ The SQL statements are replaced by a CALL to the DB2 runtime interface module.g. Also if the SQL statements do not match with the table  declarations. If there is  a mismatch in this a runtime error of  ‘­818‘. the DBRM when binded will though warning messages  . timestamp mismatch occurs  •​ All DB2 related INCLUDE statements must be placed between EXEC SQL & END EXEC  keywords for the precompiler to recognize them    COMPILE and LINK: ​ ­­­> Only COBOL code is compiled    •​ Modified precompiler COBOL output is compiled  •​ Compiled source is link edited to an executable load module  •​ Appropriate DB2 host language interface module should also be included in the link edit step(i.      DELETE  E. ­ For the Delete statement using cursors  EXEC SQL        DELETE FROM  EMP  WHERE current of EMPCUR  ​ END EXEC. along with  parameters.EXEC SQL    UPDATE EMP              Set Job   =   :New­job  WHERE current of EMPCUR   ​ END EXEC.  •​ All SQL statements are extracted and put in a Database Request Module (DBRM)    •​ Places a timestamp in the modified source and the DBRM so that these are tied.

 :EMP­RAISE.    Usage of HOST VARIABLEs:    EXEC SQL   SELECT LASTNAME.      DEPTNAME VARCHAR(36) NOT NULL. :RAISE. :PERSON­NAME. ADMRDEPT CHAR(3) NOT NULL.EMP    WHERE EMPNO = :PERSON END­EXEC.    The following results have column headings that represent the names of the host variables:  EMP­NUM PERSON­NAME EMP­SAL EMP­RAISE EMP­TTL  ======= =========== ======= ========= =======  000220 LUTZ 29840 4476 34316      Updating multiple rows: .EMP    FETCH FIRST 1 ROW ONLY  END­EXEC. For example.  One way to declare a table or view is to code a DECLARE statement in the  WORKING­STORAGE SECTION or LINKAGE SECTION within the DATA  DIVISION of your COBOL program.      MGRNO CHAR(6) . WORKDEPT    INTO :CBLNAME.  EXEC SQL   SELECT EMPNO. :EMP­TTL   FROM DSN8810.DEPT table looks like the following DECLARE statement in COBOL:  EXEC SQL   DECLARE DSN8810. the DECLARE TABLE statement for the  DSN8810. :CBLDEPT    FROM DSN8810.    Using both table column and host variable in the same SQL statement:  MOVE 4476 TO RAISE. you specify  DECLARE table­name TABLE regardless of whether the table­name refers to a  table or a view.DEPT    TABLE (DEPTNO CHAR(3) NOT NULL. LASTNAME. When you declare a table or view.  MOVE ’000220’ TO PERSON. :EMP­SAL. ​ SALARY + :RAISE   INTO :EMP­NUM. Specify the name of the table and list each  column and its data type.      LOCATION CHAR(16) )  END­EXEC. SALARY.

WORKDEPT INTO :PEMP FROM DSN8810. say :PEMP.EMP SET PHONENO = :NEWPHONE:PHONEIND WHERE EMPNO = :EMPID END-EXEC.ACT VALUES (:HV-ACTNO. FIRSTNME. you can substitute the name of a structure. Update a row with null value: EXEC SQL UPDATE DSN8810. :MIDINIT. :FIRSTNME. *************** Usage of cursors ********************* --> Each and every cursor is associated with a table.EMPNO=Y. EXEC SQL UPDATE DSN8810. :HV-ACTDESC) END-EXEC. :HV-ACTKWD. MIDINIT. :LASTNAME.EMP X WHERE EXISTS (SELECT * FROM DSN8810. The example then reads: EXEC SQL SELECT EMPNO.MOVE ’D11’ TO DEPTID. FIRSTNME.VEMP WHERE EMPNO = :EMPID END-EXEC.10 * SALARY WHERE WORKDEPT = :DEPTID END-EXEC. multiple tables require multiple cursors to access them --> ​ If SQLCODE = 100 means that end-of-table is reached --> Do not mention the host variables with the SELECT clause when you have to return multiple rows.RESPEMP AND . and :WORKDEPT. LASTNAME. MIDINIT. So for this reason the FETCH statement is important when CURSOR's are used.EMP SET SALARY = 1. Only after FETCH statement is executed with host variables only then the rows are retrieved into the table. Inserting Data​ : EXEC SQL INSERT INTO DSN8810.PROJ Y WHERE X. SALARY FROM DSN8810. Create Cursor: EXEC SQL DECLARE C1 CURSOR FOR SELECT EMPNO. that contains :EMPNO. Null indicator should be: -1 if data is null 0 if data is notnull +ve if data is truncated when passed to the host variable Move the whole row into a group that has the host variables as elementary items If you want to avoid listing host variables. LASTNAME.

:HV-FIRSTNME.PROJNO=:GOODPROJ) FOR UPDATE OF SALARY. Positioned DELETE: EXEC SQL DELETE FROM DSN8810. :HV-SALARY :IND-SALARY END-EXEC. PIC S9(9) COMP-4.EMP END-EXEC.Y. With rowset positioning a particular row can be updated/deleted. LASTNAME. let say EXEC SQL UPDATE DSN8810.EMP WHERE CURRENT OF C1 END-EXEC. :HV-LASTNAME. Preparing embedded SQL statements in COBOL: 1) Mandatory to declare SQL communication area: A COBOL program that contains SQL statements must include one or both of the following host variables: a) An SQLCODE variable declared as PIC S9(9) BINARY. :HV-MIDINIT. :HVA-LASTNAME. SALARY FROM DSN8810. PIC S9(9) COMP-5. Positioned Update: If FOR UPDATE is mentioned in the CURSOR DECLARE statement then ​ positioned update can be done as follows. Cursor CLOSE: EXEC SQL CLOSE C1 END-EXEC. :HVA-SALARY :INDA-SALARY END-EXEC. or PICTURE S9(9) COMP b) An SQLSTATE variable declared as PICTURE X(5) The above declarations can go in WORKING STORAGE SECTION OR DATA DIVISION .EMP SET SALARY = 50000 WHERE CURRENT OF C1 END-EXEC.EMP SET SALARY = 50000 FOR CURSOR C1 FOR ROW 5 OF ROWSET END-EXEC. Fetch rows: EXEC SQL FETCH C1 INTO :HV-EMPNO. EXEC SQL FETCH NEXT ROWSET FROM C1 FOR 20 ROWS INTO :HVA-EMPNO. EXEC SQL UPDATE DSN8810. ********* ---> A cursor created with rowset positioning can fetch multiple rows at a time: EXEC SQL DECLARE C1 CURSOR WITH ROWSET POSITIONING FOR SELECT EMPNO.

Use a CASE expression to list the full name of the division to which each employee belongs. but who are not fully paid on commission: SELECT EMPNO. find all employees who earn more than 25 percent of their income from commission. LASTNAME. SELECT REF_ID. SELECT REF_ID.PAYMT_PAST_DUE_CT;    ​ Example 4:​ This example shows how to group the results of a query by a CASE expression without having to re-type the expression. CASE statements:         Example 1 (simple-when-clause):​ Assume that in the EMPLOYEE table the first character of a department number represents the division in the organization. WORKDEPT.1)  WHEN 'A' THEN 'Administration'  WHEN 'B' THEN 'Human Resources'  WHEN 'C' THEN 'Design'  WHEN 'D' THEN 'Operations'  END  FROM EMPLOYEE;  Example 2 (searched-when-clause):​ You can also use a CASE expression to avoid "division by zero" errors. From the EMPLOYEE table. SELECT EMPNO. DB2® performs the division before performing the CASE statement and an error occurs along with the results.  CASE SUBSTR(WORKDEPT. the CASE expression would prevent the errors. Using the sample employee table.Alternatively.  CASE  WHEN PAYMT_PAST_DUE_CT=0 THEN 0  WHEN PAYMT_PAST_DUE_CT>0 THEN  SUM(BAL_AMT/PAYMT_PAST_DUE_CT)  END  FROM PAY_TABLE  GROUP BY REF_ID. you can include an SQLCA. In the following query.25;  Example 3 (searched-when-clause):​ You can use a CASE expression to avoid "division by zero" errors in another way. SALARY+COMM FROM EMPLOYEE  WHERE (CASE WHEN SALARY=0 THEN 0  ELSE COMM/(SALARY+COMM)  END) > 0. and average salary.1. In the first query. The following queries show an accumulation or summing operation.PAYMT_PAST_DUE_CT. EXEC SQL INCLUDE SQLCA END-EXEC. if the CASE expression is included in the SUM aggregate function. Instead of finding these values for each . minimum.PAYMT_PAST_DUE_CT;​ However. which contains the SQLCODE and SQLSTATE variables. the CASE expression screens out the unwanted division because the CASE operation is performed before the division. find the maximum.  SUM(CASE  WHEN PAYMT_PAST_DUE_CT=0 THEN 0  WHEN PAYMT_PAST_DUE_CT>0 THEN  BAL_AMT/PAYMT_PAST_DUE_CT  END)  FROM PAY_TABLE  GROUP BY REF_ID.PAYMT_PAST_DUE_CT.

​ Without concurrency control. and reads and updates data about items on hand. based on what they read.*) MEMBER(ABC) Example: Rebinds the plan and drops the entire package list: REBIND PLAN(PLANA) NOPKLIST CONCURRENCY/LOCKS: LOCKS: khbkh Definition: Concurrency is the ability of more than one application process to access the same data at essentially the same time. reads a table of data about customers.(*)) REBIND PLAN: Example: Rebinds PLANA and changes the package list: REBIND PLAN(PLANA) PKLIST(GROUP1.EMP) X  GROUP BY CASE_DEPT;      DB2 PLAN/PACKAGE: each package corresponds to a single DBRM All packages can be grouped together to form a PLAN. IF a collection of DBRM's is made as a plan then any change in one DBRM results in rebinding of the whole PLAN REBIND PACKAGE: REBIND PACKAGE (LEDGER. the operations appear concurrent. A and B. .*. Advantage of grouping all PACKAGES instead of using them as directly DBRM's is that. Conceptual background:​ Concurrency must be controlled to prevent lost updates and such possibly undesirable effects as unrepeatable reads and access to uncommitted data.CASE WHEN WORKDEPT = 'A00' OR WORKDEPT = 'E21'  THEN 'A00_E21'  WHEN WORKDEPT = 'D11' OR WORKDEPT = 'E11'  THEN 'D11_E11'  ELSE WORKDEPT  END AS CASE_DEPT  FROM DSN8910. assume that you want to combine some departments into the same group. and both calculate new values for one of its columns.AVG(SALARY)  FROM (SELECT SALARY.*) REBIND PACKAGE (LEDGER. Two operations on the same data. Example: An application for order entry is used by many transactions simultaneously. Each transaction makes inserts in tables of invoices and invoice items. two processes. To the users. by two simultaneous transactions.MAX(SALARY).department. Lost updates. might both read the same row from the database. might be separated only by microseconds. If A updates the row with its new value. SELECT CASE_DEPT.MIN(SALARY). A’s update is lost. and then B updates the same row.

Without control. That means when the application starts all the tables. if A’s value is not later committed. partions are locked ACQUIRE(USE) : means the lock is acquired when the SPECIFIC partition/table space/table are accessed *********IMP****** ACQUIRE(ALLOCATE) and RELEASE(COMMIT) options are not allowed *******IMP***********if RELEASE(COMMIT) is used . but cursor is declared with HOLD option the LOCK is still maintained post the commit position CURRENTDATA(YES/NO): ​ To guarantee data stability when a read only cursor is accessing data with CS isolation level READ ONLY is specified when cursor is delcared Interview Questions: Q7) After a table is defined. Different isolation levels Cursor stability: once the commit or rollback happens any other application can access Repeatable read: If RR is placed exclusive locks are put on the table. Best for static tables.Access to uncommitted data. Otherwise RR has to be used Uncommited READ: only relates to FETCH and SELECT Helps you read uncomitted changes in the table. is used lock is released every time after an update is made to the table ACQUIRE(ALLOCATE): means the lock is acquired when the plan is allocated. can columns be removed? NO . Unrepeatable reads. B’s calculations are based on uncommitted (and presumably incorrect) data. data retrieval is very fast http://db2portal. no other transaction can access that particular row until tarnsaction that held the record with RR is completed CS--> More performance RR--> more integrity Read stability: same a RR but the difference is no one can modify the the row or page but transactions can insert data. If there is no requirement that same number of rows have to fetched when the transaction is repeated on the A reads the first row again and must find the same values it read the first time. ​ Some processes require the following sequence of events: A reads a row from the database and then goes on to process other SQL requests. RELEASE(DEALLOCATE) deallocate is useful db2 applications where the sql statements make a lot of updates are made to the table.blogspot.html BIND options: Acquire/Release: RELEASE(COMMIT). process B could have changed the row between the two read operations. Later. Because if COMMIT happens the lock is not released If release(commit). that is when there are many instances of commit. process A might update a value in the database. and process B might read that value before it was committed. RS can be used . Then. table spaces.​ Also without concurrency control. but backed out.

BP1...GS A65) Use SELECT COUNT(*) . and is made up of either 4K or 32K pages...) (PART2. and host variables. DBRM: SYSIBM. The data types are SMALLINT. DELETING A PLAN Q24) What will the FREE command do to a plan? A24) It will drop(delete) that existing plan. CHAR..SYSSTMT PLAN: SYSIBM..SYSPLANS . ​ The SYSIBM. BP2. DECIMAL. Q12) How many buffer pools are there in DB2? A12) There are four buffer pools: BP0. VARCHAR. INTEGER. the table space is put in check pending status.SYSSTMT table of the DB2 catalog Q11) What is a buffer pool? A11) A buffer pool is main storage that is reserved to satisfy the buffering requirements for one or more tablespaces or indexes. else rollback Q6) What information is used as input to the bind process? A6) The database request module produced during the pre-compile. So ideally a parent table must be update before a child table is updated Q21) What are data types? A21) They are attributes of columns. DATE and TIME. TWO PHASE COMMIT:​ phase one: all the particpants are asked about their job.Q65) How would you find out the total number of rows in a table? .) When a table having referential integrity is altered. FLOAT. responses are collected in this phase only PHASE 2 if everybody says ok then commit. and BP32. DB2 DBA: CREATE TABLESPACE TB IN DATABASENAME using storagegroup stgname priqty secqty erase no --> do not erase tables when table space is dropped locksize any bufferpool bp0 close no <== close the table spave when not accessed freepage 5 (Percentage of space that has to be left before any other table space starts) pctfree 10 (percentage of each page that has to be left free) SEGSIZE 32 (--segmented table space) more than one table (4 to 64) in multiples of four NUMPARTS2 (1 to 254) (part1. literals.

explicit close is required to close the cursor Q54) What is the physical storage length of each of the following DB2 data types: DATE.Q36) What is the format (internal layout) of “TIMESTAMP”? A36) This is a seven part value that consists of a date (yymmdd) and time(hhmmss and microseconds). Q46) What information can you find in SYSIBM. Lets say SQL query is accessing 500 rows but requires only 10 rows from that for the use RR-500 RS-10 CS-1 UR-none(read only) Types of Locks: Intent none:(Read only) Lock Owner can only read the data.SYSINDEXES SYSIBM.SYSLINKS table contains information about the links between tables created by referential constraints. TIME. Q47) Where would you find information about the type of database authority held by the user? A47) SYSIBM.. cannot modify Applied on the table space/table Shared/Exclusive/Update Q44) What information is held in SYSIBM. Q45) What information is contained in a SYSCOPY entry? A45) Included is the name of the database.SYSCOPY table contains information about image copies made of the tablespaces.SYSVIEWS Q148) What is Skeleton cursor table (SKCT)? A148) The Executable form of a Plan.SYSDBAUTH.SYSLINKS table? A46) The SYSIBM. the table space name.SYSCOPY? A44) The SYSIBM. SYSIBM.) as well as the date and time each copy was made. and the image copy type(full or incremental etc. TIMESTAMP? A54) DATE: 4bytes TIME: 3bytes TIMESTAMP: 10bytes Q55) What is the COBOL picture clause of the following DB2 data types: DATE.sct02 table CURSOR DELCARED WITH HOLD OPTION is not closed after a commit. TIME. TIMESTAMP? . This is stored in sysibm.

GS A123) The number of distinct values a column or columns contain Q150) Can we declare DB2 HOST variable in COBOL COPY book? A150) NO. Q109) What is QUIESCE? A109) A QUIESCE flushes all DB2 buffers on to the disk. .GS A115) This is generated when the consistency tokens in the DBRM and the load module are different. Q122) What is filter factor? A122) One divided by the number of distinct values of a column. This gives a correct snapshot of the database and should be used before and after any IMAGECOPY to maintain consistency. Q108) What is CHECK PENDING ? A108) When a table is LOADed with ENFORCE NO option. Q113) What is sqlcode -922 ? A113) Authorization failure Q114) What is sqlcode -811? A114) SELECT statement has resulted in retrieval of more than one row. at the time of Pre-compilation we get the host variable not defined. because pre-compiler will not expand COBOL COPY book. Q65) How can you quickly find out the number of rows updated after an update statement? A65) Check the value stored in ​ SQLERRD(3).A55) DATE: PIC X(10) TIME : PIC X(08) TIMESTAMP: PIC X(26) Utility to run a plan Use IKJEFT01 utility program to run the above DSN command in a JCL. Q145) What is the error code -803 ? A145) unique index violation Q167) What is the meaning of -805 SQL return code? A167) Program name not in plan. Q123) What is index cardinality? . Bind the plan and include the DBRM for the program named as part of the plan Q115) What does the sqlcode of -818 pertain to? . It means that the LOAD utility did not perform constraint checking. So we declare it either in DCLGEN with EXEC SQL INCLUDE DCLGEN name END-EXEC or we directly hardcode it in the working storage section. then the table is left in CHECK PENDING status. If we declare DB2 host variable in COBOL COPY book.

Just used to maintain different regions.**********>>> MUST ALWAYS BE TEST OWNER(????) .????????) .**********>>> FOR EACH PLAN) QUALIFIER(TEST) . Follow the example: BIND PLAN(PLANNAME) PKLIST(RR16388.**********>>> ENTER MEMBER NAME SEALAND. Next important thing is COLLECTION ID.PROD) VERSION(PROD) 1) What is happening above is that same package has two versions.**********>>> ENTER YOUR TSO ID ACTION(REPLACE) RETAIN VALIDATE(BIND) ISOLATION(CS) FLAG(I) ACQUIRE(USE) RELEASE(COMMIT) EXPLAIN(YES) PLAN EXECUTION: DSN SYSTEM(DB2T) RUN PROG(TESTPROG) PLAN(TESTPLAN) END PACKAGE parameters. .????????. .**********>>> (MULTIPLE MEMBERS SEALAND. BIND PACKAGE(RR16388.**********>>> ENTER PLAN NAME PKLIST(SEALAND.PLAN CREATION: BIND PLAN(????????) .????????. Collection ID is the HLQ of the package name.TEST) VERSION(TEST) BIND PACKAGE(RR16388.*) 2) All the packages with collection ID "RR16388" are bound into a PLAN . One being TEST and the other PROD.

The code can be zero (0). 0 means successful execution.  .    Negative means unsuccessful with an error. negative or positive.3) SQLERROR(CONTINUE|NOPACKAGE) : If there is an SQL error create a PACKAGE. NOERROR BIND PARAMETERS: 1) MEMBER(MEMNAME): MEMBER is the member name in which the DBRM is stored 2) LIB('DBRMLIB'): PDS in which DBRM is present 3) ISOLATION LEVEL(CS|RR|RS|UR) 4) ACTION(REPLACE) REPLACE is default replace the PLAN with the same name 5) ACQUIRE(ALLOCATE|USE) RELEASE(COMMIT|DEALLOCATE) 6) VALIDATE(RUN|BIND): Validate for PACKAGE not found and privilege issues during RUN time iF RUN is mention. Else throw error message during the bind process 7) EXPLAIN(YES|NO) : PLAN_TABLE is updated with the access path by the optimizer SQL CODES: SQLCODE The SQLCODE field contains the SQL return code.

  ­503 Updating column needs to be specified.  An example is +100 which means no rows found.  ­216 Not the same number of expressions on both sides of the comparison in a  SELECT .    ­501 Cursor not open on FETCH.    Positive means successful execution with a warning.An example is ­911 which means a timeout has occurred with a ​ rollback​ .  ­224 FETCH cannot make an INSENSITIVE cursor SENSITIVE.  ­545 Check constraint preventing the INSERT/UPDATE.  Here is a more comprehensive list of the SQLCODEs for DB2: [​ edit​ ] Zero (Successful) 0 Successful  [​ edit​ ] Negative values (Errors) ­102 String constant is too long.  ­502 Opening cursor that is already open.  ­206 Column does not exist in any table of the SELECT.  ­551 Authorization failure    ­747 The table is not available. No rollback.  ­805 DBRM or package not found in plan.  ­927 The language interface was called but no connection had been made.  ­811 More than one row retrieved in SELECT INTO.  ­913 Deadlock or timeout.  ­229 The locale specified in a SET LOCALE statement was not found.    ­904 Unavailable resource.    ­204 Object not defined to DB2.  ­205 Column name not in table.  ­117 The number of values in the INSERT does not match the number of columns. ­LEN field with the right data length not set.  ­311 Varchar.  ­818 Plan and program: timestamp mismatch.  ­199 Illegal use of the specified keyword. Rollback has been done.  ­922 Authorization needed.  ­181 Bad data in Date/Time/Timestamp.  ­180 Bad data in Date/Time/Timestamp.  ­536 Referential integrity (DELETE RESTRICT rule) preventing the DELETE.    ­803 Duplicate key on insert or update. Someone else is locking your data.  ­936  ­1741  .    ­305 Null indicator needed. insert or update.  ­530 Referential integrity preventing the INSERT/UPDATE  ­532 Referential integrity (DELETE RESTRICT rule) preventing the DELETE.    ­482 The procedure returned no locators.  ­911 Deadlock or timeout.

if you set the db2 field to a value that is stored in the host variable and for example assume that host variable does have some value and if the respective null indicator has -1 in it then the value in the host variable will not be inserted. If you doubt that the returned value might be null use a null indicator.­20000  ­302 Data that is fetched from DB2 is more than the host variable    [​ edit​ ] Positive Values (Warnings) +100 Row not found or end of cursor. If rows are retrieved only relevant segments are accessed CREATE TABLESPACE MYTS  IN MYDB  USING STOGROUP MYSTOGRP  PRIQTY 30720  SECQTY 10240  SEGSIZE 32  LOCKSIZE TABLE  BUFFERPOOL BP0  CLOSE NO;    Bufferpool: When DB2 tables are picked up from the disk to the Main memory The area of Main memory that will be used by the DB2 tables is bufferpool Segmented table space: One table per page. VIEW:--> WITH CHECK OPTION WILL THROW ERRORS IF ANY CREATE VIEW PRIORITY_ORDERS . While update if you want to move null values then pass -1 into the null indicator and then update/insert the table ******IMP*** ​ while update .  +802 The null indicator was set to ­2 as an arithmetic statement didn't work. ALTER TABLE: ALTER TABLE IBMGRP.ALTER ALTER COLUMN NAME SET DATA TYPE VARCHAR(100).  +231 FETCH after a BEFORE or AFTER but not on a valid row.    Null Indicators: While select. it will be set to NULL S9(4) USAGE COMP means --> Small int as it occupies two bytes SEGMENTED table space: Each page is of size 4 kb to 64 KB A page is divided into segments Each segment can relate to only one table. So if a page lock is applied only relevant segments to the particular table are locked.  +304 Value cannot be assigned to this host variable because it is out of range.  +222 Trying to fetch a row within a DELETE statement.  +223 Trying to fetch a row within an UPDATE statement.

. Trigger​ :<-. even though the new record would not be visible to the view that was used to add it. Had the view not been created with the WITH CHECK OPTION clause....] <WhereClause> <GroupByClause> <HavingClause> <OrderByClause> <FetchFirstClause> Order of execution: · The DISTINCT clause · The FROM clause · The WHERE clause · The GROUP BY clause · The HAVING clause · The ORDER BY clause · The FETCH FIRST clause Where​ can be used with : · Relational Predicates (Comparisons) · BETWEEN · LIKE · IN · EXISTS · NULL Relational predicates .AS SELECT * FROM ORDERS WHERE RESPONSE_TIME < 4 WITH CHECK OPTION Now..Every time an insert happens the emp no is incremented by 1 CREATE TRIGGER NAME_INC AFTER INSERT ON IBMGRP..ALTER FOR EACH ROW MODE DB2SQL UPDATE NAMID SET NAMID = NAMID + 1. the insert operation would have been successful.Always use it with where to avoid mass delete of rows DELETE FROM SALES WHERE COMPANY = ‘XYZ’ The SELECT statement​ : SELECT <DISTINCT> [* | [Expression] <<AS> [NewColumnName]> . suppose a user tries to insert a record into this view that has a RESPONSE_TIME value of 6. Delete​ <-. The insert operation will fail because the record violates the view’s definition.] FROM [[TableName] | [ViewName] <<AS> [CorrelationName]> .

SUM. LASTNAME FROM EMPLOYEES WHERE LASTNAME LIKE ‘S%’ IN predicate: SELECT LASTNAME.COUNT(*) are used. SALARY FROM EMPLOYEES WHERE SALARY BETWEEN 10000. if you wanted to find out which values found in the column named DEPTNO in a table named DEPARTMENT are used in the column named WORKDEPT found in a table named EMPLOYEES.00 >= 10K and <= 20000 The LIKE predicate: · The underscore character (_) is treated as a wild card character that stands for any single alphanumeric character. The EXISTS predicate is always followed by a subquery​ . · The percent character (%) is treated as a wild card character that stands for any sequence of alphanumeric characters.00 AND 20000.AVG. Thus.· · · · · · · < (Less than) > (Greater than) <= (Less than or equal to) >= (Greater than or equal to) = (Equal to) <> (Not equal to) NOT (Negation) BETWEEN: SELECT EMPNO. SELECT EMPNO. and it returns either TRUE or FALSE to indicate whether a specific value is found in the result data set produced by the subquery. you could do so by executing a SELECT statement that looks something like this: SELECT DEPTNO. DEPTNAME FROM DEPARTMENT WHERE EXISTS (SELECT WORKDEPT FROM EMPLOYEES WHERE WORKDEPT = DEPTNO) AGGREGATE FUNCTION: When MAX. WORKDEPT FROM EMPLOYEES WHERE WORKDEPT IN (SELECT DEPTNO FROM DEPARTMENTS WHERE DEPTNAME = ‘OPERATIONS’ OR DEPTNO = ‘SOFTWARE SUPPORT’) *** The EXISTS CLAUSE ***** The EXISTS predicate is used to determine whether or not a particular value exists in a given table. the rows having null values are discarded.MIN. FOr example: MyTable .

Right.WORKDEPT = D. AVG(SALARY) AS AVG_SALARY FROM DEPARTMENT D.00 Inner join Vs Outer Join Inner join only returns matching rows Outer join returns matching rows and non matching rows(Depending on Left.These locks are obtained at table level Intent share : Lock is obtained at a row or page level. DEPTNAME FROM EMPLOYEES E LEFT OUTER JOIN DEPARTMENT D ON​ E. The above two locks are only the ones which can get a lock at row level or page level Share/Update/eXclusive locks:. Any duplicates will be eliminated./ user can update other rows Share: Everybody can read the rows in table but nobody can update the table Update: For the application to update any data . other application . Union All will not eliminate duplicates Types of Locks: Intent Share/ Intent Upddate. lock has to be promoted to X EXEC SQL LOCK TABLE TAB1 IN SHARE MODE END-EXEC . EMPLOYEES E WHERE E.DEPTNO Union Vs Union all: Union will return combined result of two different queries .DEPTNO GROUP BY DEPTNAME HAVING AVG(SALARY) > 30000.Full) SELECT LASTNAME.ID 1 2 3 4 5 Name John Jack Jim Joe Josh Amount 37 NULL  5 12 NULL      When avg(amount) is asked then DB2 will consider only 37+5+12/3 not (37+NULL + 5+ NULL+ 12)/5 Having Clause: SELECT DEPTNAME.WORKDEPT = D.

there is no other place where in we can retrieve rows . Declare cursor can be used with UPDATE/DELETE (In the sence select statement should be there with UPDATE / DELETE statements like FOR UPDATE OF) INSERT is not allowed with DECLARE CURSOR​ .aspx If SELECT statement has to be used within DECLARE CURSOR.Lets say SQL query is accessing 500 rows but requires only 10 rows from that for the use RR-500 RS-10 CS-1 UR-none(read only) DECLARE CURSOR C1 FOR SELECT WITH RR/RS/CS/UR The above will override bind isolation levels Example for DB2 SQLCODE: -922 READY DSN SYSTEM(DB2R) DSN BIND PLAN(FCURF2) PKLIST(DB2RLOC.*) ACT(REP) ISOLATION(CS) DSNT210I -DB2R BIND AUTHORIZATION ERROR USING R06388 AUTHORITY PLAN = FCURF2 PRIVILEGE = BINDADD DSNT201I -DB2R BIND FOR PLAN FCURF2 NOT SUCCESSFUL DSN EXPLAIN (NO) OWNER(IBMGRP) DSNE118E EXPLAIN NOT VALID COMMAND DSN END Authorization(BINDADD) not present to add a DBRM to a PACKAGE DB2 FAq's: