What is DB2 ( IBM Database 2 )?
DB2 is subsystem of the MVS operating system. It is a Database Management System ( DBMS ) for that operating system.
What is an access path?
The path that is used to get to data specified in SQL statements.
What is an alias?
It is an alternate name that can be used in SQL training Hyderabad statements to refer to a table or view in the same or remote DB2 subsystem
Explain what a plan?
Plan is a DB2 object (produced during the bind process ) that associates one or more database request modules with a plan name.
What information is used as input to the bind process?
The database request module produced during the pre-compile. The SYSIBM.SYSSTMT table of the DB2 catalog.
What is meant by the attachment facility?
The attachment facility is an interface between DB2 and TSO, IMS/VS, CICS, or batch address spaces. It allows application programs to access DB2.
What is meant by AUTO COMMIT
AUTO COMMIT is a SPUFI option that commits the effects of SQL statements automatically if they are successfully executed.
What is a base table ?
A base table is real table – a table that physically exists in that there are physical stored records.
What is a buffer pool ?
A buffer pool is main storage that is reserved to satisfy the buffering requirements for one or more tablespaces or indexes, and is made up of either 4K or 32K pages.
On the create tablespace, what does the CLOSE parameter do?
CLOSE physically closes the tablespace when no one is working on the object. DB2 (release 2.3 ) will logically close tablespaces.
What will the COMMIT accomplish?
COMMIT will allow data changes to be permanent. This then permits the data to be accessed by other units of work. When a COMMIT occurs, locks are freed so other applications can reference the just committed data.
What is cursor stability?
It is cursor stability that “tells” DB2 that database values read by this application are protected only while they are being used. (Changed values are protected until this application reaches the commit point ). As soon as program moves from one row to another. Other programs may read or the first row.
What is the function of the Data Manager?
The Data Manager is a DB2 component that manager the physical databases. It invokes other system components, as necessary, to perform detail function such as locking, logging, and physical I/O operations ( such as search, retrieval, update, and index maintenance).
What is a data page?
A data page is a unit of retrievable data, either 4K or 32K ( depending on how the table is defined ), containing user or catalog information.
What is Declaration Generator ( DCLGEN )?
DCLGEN is a facility that is used to generate SQL statements that describe a table or view. These table or view descriptions are then used to check the validity of other SQL statements at precompile time. The table or view declares are used by the DB2I utility DCLGEN to build a host language structure, which is used by the DB2 precompiler to verify that correct column names and data types have been specified in the SQL statement.
What will the FREE command do to a plan?
It will drop ( delete ) that existing plan.
What is a host variable?
This is a data item that is used in an SQL statement to receive a value or to supply a value. It must be preceded by colon (:) to tell DB2 that the variable is not a column name.
What will the DB2 optimizer do?
The optimizer is a DB2 component that processes SQL statements and selects the access paths.
What is a page?
This is the unit of storage within a tablespace or index space that is accessed by DB2.
What is page space?
Page Space refers to either to an unpartitioned table, to an index space, or to a single partition of a partitioned table of index space.
What is a predicate?
A predicate is an element of a search condition that expresses or implies a comparison operation.
What is a recovery log?
A recovery log is a collection of records that describes the sequence of events that occur in DB2. The information is needed for recovery in the event of a failure during execution.
What is a Resource Control Table (RCT)? Describe its characteristics.
The RCT is a table that is defined to a DB2/CICS region. It contains control characteristics which are assembled via the DSN CRCT macros. The RCT matches the CICS transaction ID to its associated DB2 authorization ID and plan ID ( CICS attachment facility).
Where are plans stored ?
Each plan is defined uniquely in the SYSIBM SYSPLANS table to correspond to the transaction(s) that are to execute that plan.
What is meant by repeatable read?
When an application program executes with repeatable read protection, rows referenced by the program can’t be changed by other programs until the program reaches a commit point.
Describe what a storage group (STOGROUP) is?
A STOGROUP is a named collection of DASD volumnes to be used by table spaces and index spaces of databases. The volumns of STOGROUP must be of the same device type.
How would you move a tablespace ( using STOGROUP ) to a different DASD volume allocated to that tablespace?
If the tablespace used is only allocated do that STOGROUP :
ALTER STOGROUP- add volume (new ) delete volume (old )
REORG TABLESPACE or RECOVER TABLESPACE
Create a new STOGROUP that points to the new volume. ALTER the tablespace and REORG or RECOVER the tablespace.
What is the format (internal layout) of “TIMESTAMP”?
This is a seven part value that consists of a date (yymmdd) and time (hhmmss and microseconds)
What is meant by a unit of recovery?
This is a sequence of operations within a unit of work (i. e. , work done between commit points).
Can DB2 be accessed by TSO users? If yes, which command is used to invoke DB2
DB2 can be invoked by TSO users by using the DSN RUN command.
What is a DB2 catalog ?
The DB2 catalog is a set of tables that contain information about all of the DB2 objects ( tables, views, plans etc ).
What information is held in SYSIBM.SYSCOPY?
The SYSIBM.SYSCOPY table contains information about image copies made of the tablespaces.
What information is contained in a SYSCOPY entry?
Included is the name of the database, the table space name, and the image copy type (full or incremental etc..) as well as the date and time each copy was made.
What information can you find in SYSIBM.SYSLINKS table?
The SYSIBM.SYSLINKS table contains information about the links between tables created by referential constraints.
Where could you look if you had a question about whether a column has been defined as an index?
This information can be found in SYSIBM.SYSINDEXES.
What is the SQL Communications Area and what are some of its key fields?
It is a data structure that must be included in any host-language program using SQL. It is used to pass feedback about the SQL operations to the program. Fields are return codes, error messages, handling codes and warnings.
What is DCLGEN?
DCLGEN stands for declarations generator, it is a facility to generate DB2 SQL data structure in COBOL or PL/I programs.
How do you leave the cursor open after issuing a COMMIT? (for DB2 2.3 or above only )?
Use WITH HOLD option in DECLARE CURSOR statement. But, it has not effect in pseudo-conversational CICS programs.
What is the physical storage length of each of the following DB2 data types : DATE, TIME, TIMESTAMP?
DATE: 4 bytes
TIME: 3 bytes
TIMESTAMP: 10 bytes
What is DCLGEN?
DeClarations GENerator: used to create the host language copy books for the table definitions. Also creates the DECLARE table.
Is DECLARE TABLE in DCLGEN necessary? Why it used?
It not necessary to have DECLARE TABLE statement in DCLGEN. This is used by the pre-compiler to validate the table-name, view-name, column name etc.., during pre-compile.
How is a typical DB2 batch program executed?
There are two methods of executing a DB2 – batch program
Use DSN utility to run a DB2 batch program from native TSO. An example is shown:
RUN PROGRAM(EDD 47/0BD) PLAN(EDD470BD) LIB(EDGS01T.OBJ.LOADLIB)
Use IKJEFT01 utility program to run the above DSN command in a JCL.
Name some of field from SQLCA?
SQLCODE, SQLERRM, SQLERRD
How do you do the EXPLAIN of a dynamic SQL statement?
There are two methods to achieve this:
Use SPUFI or QMF to EXPLAIN the dynamic SQL statement
Include EXPLAIN command in the embedded by dynamic SQL statements
How do you simulate the EXPLAIN of an embedded SQL statement in SPUFI/QMF ? Give an example with a host variable in where clause) ?
Use a question mark in place of a host variable (or an unknown value). For instance,
SELECT EMP_NAME FROM EMP WHERE EMP_SALARY > ?
What are the isolation levels possible ?
CS: Cursor Stability
RR: Repeatable Read
What is the difference between CS and RR isolation levels ?
CS: Release the lock on a page after use
RR: Retains all locks acquired till end of transaction
When do you specify the isolation level? How ?
During the BIND process (ISOLATION LEVEL is a parameter for the bind process ).
How does DB2 determine what lock-size to use?
There are three methods to determine the lock-size. They are;
-Based on the lock-size given while creating the tablespace.
-Programming can direct the DB2 what lock-size to use
-If lock-size ANY is specified, DB2 usually chooses a lock-size of PAGE
What is lock escalation?
Promoting a PAGE lock-size to table or tablespace lock-size when a transaction has acquired more lock than specified in NUMLKTS. Locks should be taken on objects in single tablespace for escalation to occur.
What are the various locks available?
SHARE, EXCLUSIVE, UPDATE
What is ALTER?
SQL command used to change the definition of DB2 objects.
What is a DBRM, PLAN?
DBRM: Data Base Request Module, has the SQL statements extracted from the host language program by the pre-compiler.
PLAN: A result of the BIND process. It has the executable code for the SQL statements in the DBRM.
What is ACQUIRE/RELEASE in BIND?
Determine the point at which DB2 acquires or releases locks against table and tablespaces, including intent locks.
What else is there in the PLAN apart from the access path?
PLAN has the executable code for the SQL statements in the host program
What happens to the PLAN if index used by it is dropped?
Plan is marked as invalid. The next time the plan is accessed, it is rebound.
What are PACKAGES?
They contain executable code for SQL statements for one DBRM.
What are the advantages of using a PACKAGE?
The advantages of using PACKAGE are :
Avoid having to bind a large number of DBRM members into a plan
Avoid cost of a large bind
Avoid the entire transaction being unavailable during bind and automatic rebind of a plan
Minimize fallback complexities if changes result in an error.
What is a collection?
A user defined name that is the anchor for packages. It has not physical existence. Main usage is to group packages.
How would you print the output of an SQL statement from SPUFI?
Print the output dataset.
What is dynamic SQL?
Dynamic SQL is a SQL statement created at program execution time.
When is the access path determined for dynamic SQL?
At run time, when the PREPARE statement is issued.
Suppose I have a program which uses a dynamic SQL and it has been performing well till now. Off late, I find that performance has deteriorated. What happened?
There may be one of the following reasons:
probably RUN STATS is not done and the program is using a wrong index due to incorrect stats.
probably RUN STATS is done and optimizer has chosen a wrong access path based on the latest statistics.
How does DB2 store NULL physically?
As an extra-byte prefix to the column value. Physically, the null prefix is Hex ’00” if the value is present and Hex ‘FF’ if it is not.
How do you retrieve the data from a nullable column?
Use null indicators. Syntax .. INTO: HOSTVAR:NULLIND
What is the picture clause of the null indicator variable?
What does it mean if the null indicator has -1, 0, -2??
-1 : the field is null;
0 : the field is not null;
-2: the field value is truncated
How do you insert a record with a nullable column?
To insert a NULL, move -1 to the null indicator. To insert a valid value, move 0 to the null indicator
What is RUNSTATS?
A DB2 utility used to collect statistics about the data value in tables which can be used by the optimizer to decide the access path. It also collects statistics used for space management. These statistics are stored in DB2 catalog tables.
When will you choose to run RUNSTATS?
After a load, or after mass updates, inserts, deletes, or after REORG.
What is the reason that MySQL statement “SELECT AVG (SALARY) FROM EMP” generates inaccurate output?
The reason for the statement generating inaccurate outcome is because of the fact that SALARY has not been declared to have NULL and at the same time the employees whose salary is not known are also counted.
Why SELECT is not preferred in embedded SQL programs?
SELECT is not preferred in embedded SQL programs for three reasons. First; if the table structure is changed by the addition or deletion of a field and the program is modified then using SELECT might retrieve the columns that the user may not use. This would lead to Input Output overhead and the chances of index only scan is also eliminated.