The DB2 RUNSTAT utility records the details of tablespace, table, index, etc in the system catalog. The RUNSTAT generates the data like space available in table space, indexes, access paths, etc. We can use the below JCL step to update the catalog statistics of DB2 tablespace TABSPAC2 and to sample 25% of the rows.//STEP1 EXEC DSNUPROC //UTPRINT DD SYSOUT=* //SYSIN DD * RUNSTATS TABLESPACE DBSET1.TABSPAC1 TABLE(ALL) SAMPLE 25 INDEX(ALL)The SYSIN parameter can be used with RUNSTATS TABLESPACE statement followed by tablespace name qualified by database name.
We can start the DB2 database by giving below command in panelDB2 ACTIVATE DSNDB001The DB2 ACTIVATE is followed by the name of the database which needs to be started.
The DB2 provides an utility RECOVER which is used to restore the tablespace. This utility uses image copy and DB2 logs to restore the changes. The following command can be used to recover the tablespace to the last image copy that was taken.RECOVER TABLESPACE DBSET1.TABSPAC1 TOLASTCOPYThe RECOVER TABLESPACE is followed by the name of tablespace qualified by the database in which it resides. The TOLASTCOPY parameter will restore the image copy in the following way. If the most recent image copy is full image copy, then the full image copy is restored in the tablespace. If the most recent image ... Read More
The MERGECOPY is just opposite of IMAGECOPY. This DB2 utlility is used to combine the multiple image copy datasets into a new full or incremental image copy. This is mainly used to restore the backup in the DB2 table.The below JCL step can be used for the incremental MERGECOPY for DB2 table TAB1 which is residing in the database DBSET1−//STEP010 EXEC DSNUPROC //COPY1 DD DSN=TEST.DB2.COPY1, DISP=(MOD, CATLG, CATLG), // UNIT=SYSDA, SPACE=(4000, (20, 20), , , ROUND) //COPY2 DD DSN=TEST.DB2.COPY2, DISP=(MOD, CATLG, CATLG), // UNIT=SYSDA, SPACE=(4000, (20, 20), , , ROUND) //SYSOUT DD SYSOUT=* //SYSIN DD * MERGECOPY TABLESPACE DBSET1.TBSPAC01 COPYDDN ... Read More
The declared temporary tables are also non-permanent tables but unlike created temporary tables they can be defined in the application program. The existence of a declared temporary table is limited to program execution. Since the declared temporary tables are created and deleted at the runtime, their entries are not stored into DB2 system table SYSIBM.SYSTABLES.The declared temporary table can be defined in the program using DECLARE GLOBAL TEMPORARY TABLE statement. The advantage of a declared temporary table over a created temporary table is that we can add constraints and indexes in these tables.
The Created temporary tables are non-permanent DB2 tables that exist as long as the process using this table is active. For example any batch program. The created temporary tables are best suited for the sequential access and hence system performance is not a concern over here.The created temporary tables can be created using the DDL statement CREATE GLOBAL TEMPORARY TABLE followed by the name of the temporary table. This statement makes the entry of the new table in DB2 system table SYSIBM.SYSTABLES with type column as ‘G’.The created temporary table should always be created using the above DDL statement before ... Read More
To get a DB2 view definition we can use the SYSIBM.SYSVIEW DB2 system table. The SYSVIEW table stores the details about all the views that exist in DB2. We can give below SQL statement to find the view definition.SELECT NAME, SEQNO, TEXT FROM SYSIBM.SYSVIEWS WHERE NAME = ‘VIEW1’ ORDER BY SEQNO;The VIEW can have definitions in multiple lines denoted by the SEQNO. That is the reason we need to use ORDER BY SEQNO so as to give the view definition in correct order. The exact definition is available in the TEXT column.
SYSIBM.SYSTABAUTH is a DB2 system table which records the privileges that users/program hold on tables and views. We can use this table to find out the list of programs accessing a particular table and what action the program is performing on the table like SELECT, UPDATE, INSERT or DELETE. The below SQL query can be fired on SYSTABAUTH in order to get list of programs.SELECT GRANTEE, SELECTAUTH, UPDATEAUTH, INSERTAUTH, DELETEAUTH FROM SYSIBM.SYSABAUTH WHERE GRANTEETYPE = ‘P’ AND TNAME = ‘TAB1’The column SELECTAUTH, UPDATEAUTH, INSERTAUTH and DELETEAUTH represents SELECT, UPDATE, INSERT and DELETE authority respectively. In the WHERE clause we will ... Read More
To find out all the indexes built on the DB2 table TAB1 we can use the DB2 system table SYSIBM.SYSINDEXES. The SYSINDEXES database has one row for every index present in DB2. We can find indexes built on a particular table using the below SQL query.SELECT NAME, UNIQUERULE, CLUSTERING FROM SYSIBM.SYSINDEXES WHERE TBNAME=’TAB1’The column UNIQUERULE in the SELECT statement returns ‘P’ for primary index and ‘U’ for alternate index. The CLUSTERING column will be returned as ‘YES’ for clustered index and ‘NO’ for non-clustered index.
The foreign key of a DB2 table can be found using SYSIBM.SYSFOREIGNKEYS table and SYSIBM.SYSRELS table. The SYSFOREIGNKEYS is a DB2 system table which contains one row for every column of every foreign key. The SYSRELS table contains details about the referential constraints. In order to find out the foreign key(s) of any table, we can use the below SQL query.SELECT B.REFTBNAME AS PARENTTABLE, COLNAME FROM SYSIBM.SYSFOREIGNKEYS A, SYSIBM.SYSRELS B WHERE A.RELNAME = B.RELNAME AND B.TBNAME = 'TAB1' AND B.REFTBCREATOR = A.CREATORWe will join SYSFOREIGNKEYS and SYSRELS table for the columns RELNAME which stores the details regarding constraint name for ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP