What is DB2?
DB2 (Database 2) is a Relational Database Management System for the MVS Operating System where, DB2 is a subsystem of MVS Operating System.IBM offers a family of DB2 products that run arrange of operating system like UNIX, LINUX, Windows, IBM, VSE,VM, and Z/OS.
Can you define COMMIT?
The data changes can be made permanent by using COMMIT. It also permits data to be accessed by other applications who can reference the committed data
What are the uses of DB2 Optimizer?
- It processes SQL statements.
- It helps to select the access path
What component checks DB2 deadlocks?
Locking services are provided by locking services component which is known as
Internal Resource Lock Manager (IRLM) and manages concurrency issues and dead locks.
Can you define SQLCA?
SQL Communication Area is a structure of variables, which are updated after every execution of SQL statements. For an application that contains executable SQL statements, only one SQLCA is needed. FORTRAN needs more than one SQLCA to be provided. For Java, SQLCA is not applicable.
Can you define CHECK constraint?
It is specified as a condition or criteria to ensure data integrity. A value to be inserted or updated to a table is tested by CHECK constraint. The CHECK constraints are created during the creation of the table.
What is SQLCA’s maximum length?
136 is the maximum length of the SQLCA.
What is BIND step in a DB2 program?
Bind step converts all the SQL statements into executable form in COBOL-DB2 program.
Can you explain SQLCODE?
Regardless of whether the application program provides an SQLCA or a stand-alone variable, SQLCODE is set by DB2 after each SQL statement is executed. DB2 conforms to the ISO/ANSI SQL standard as follows:
SQLCODE = 0, execution was successful
SQLCODE > 0, execution was successful with a warning
SQLCODE < 0, execution was not successful
SQLCODE = 100, “no data” was found. For example, a FETCH statement returned no data because the cursor was positioned after the last row of the result table.
The SQL Code looks like this:
SQL0000X
Where the 0’s are replaced by any digits. There are almost always four digits, but for a few error codes, there may be 5 digits. The final character (represented by X above) is a letter – one of the following:
- W -Warning: The statement completed, but there was some issue that could mean that everything is OK or that the statement partially failed.
- N -Error: The execution of this statement failed, though the error may be isolated to this statement.
- C -Severe System Error: Not only did the execution of this statement fail, but a system error was encountered indicating other failures are likely and other users may be impacted.
What are the common SQL error codes?
SQLCODE -180: Bad data in Date/Time/Timestamp – String representation of DATE, TIME, TIMESTAMP is invalid
SQLCODE -181: Bad data in Date/Time/Timestamp Value for DATE, TIME, TIMESTAMP is invalid
SQLCODE -199: Illegal use of the specified keyword.
SQLCODE -305: Null indicator needed
SQLCODE -311: Varchar, insert or update.
You didn’t set the -LEN field with the right data length
SQLCODE -501: Cursor not open on FETCH
SQLCODE -502: Opening cursor that is already open
SQLCODE -551: Not authorized to access DB2
SQLCODE -803:Â 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:Â Unavailable resource. Someone is locking the data you need you may choose to terminate the program
Can you explain DB2 Bind?
The process that builds access paths to the DB2 table is known as bind. The bind uses Database Request Modules from the DB2 pre-compile step as input and produces an application plan. It checks for user authentication and validates SQL statements in the DBRM(s).
What are the most asked SQLCODE errors in DB2 Interview?
SQLCODE 000: Successful
SQLCODE 100: Row not found
SQLCODE -205: Column name is not a column of the table
SQLCODE -305: Null value cannot be assigned to a host variable
SQLCODE -313: Number of host variables declared in not equal to number of parameter markers
SQLCODE -501: Cursor is not opened
SQLCODE -502: Multiple open of cursor
SQLCODE -503: olumn cannot be updated because it is not defined in declare statement
SQLCODE -504: Cursor name not defined
SQLCODE -551/-552: Authorization for user id not found
SQLCODE -803: Duplicate insert
SQLCODE -811: Select statement fetches more than one row, in case of Singleton SELECT
SQLCODE -818: Timestamp mismatch
SQLCODE -922: Not authorized on a particular resource
SQLCODE -904: Resource not available
SQLCODE -911: Timeout dead lock
SQLCODE -913: Deadlock with rollback
SQLCODE -530: Foreign key not found
SQLCODE -532: Delete not allowed.
What are the three types of page locks that can be held.
What is buffer pool?
The buffer pool is a reserved main storage, which is to satisfy the buffering requirements for one or more table spaces or indexes. It can be made up of either 4K or 32K pages.
Can you explain SQLSTATE?
SQLSTATE is also set by DB2 after the execution of each SQL statement. Thus, application programs can check the execution of SQL statements by testing SQLSTATE instead of SQLCODE.SQLSTATE is a 5-byte character string variable in the SQLCA.
What is DB2 catalog?
The catalog comprises several DB2 tables and can be accessed via SQL. The catalog contains details about DB2 objects obtained from the DDL (Data Definition Language) when an object is created or altered or from DCL (Data Control Language) when an authorization is granted on an object or a group of objects.
What is Data Manager?
The physical database is managed by the DB2 component called Data manager. It invokes other system components to perform logging, locking etc.
Can you explain storage group (STOGROUP)?
STOGROUP is a named collection of DASD volumes, which is to be used by index spaces and table spaces of the database.
What does DSNDB07 database do?
DSNDB07 is where DB2 does its sorting. It includes DB2’s sort work area and external storage.
Can you define predicate?
Predicate is an element of a search condition. It expresses or implies a search condition.
Can you explain Declaration Generator (DCLGEN)?
Declaration Generator is a facility that is used to form SQL statements that describes a table or view. At pre-compile time, the table or view descriptions are then used to check the validity of SQL statements.
What are the buffer pools in DB2?
There are four buffer pools in DB2 and they are:
Can you explain clustering index?
Clustering index is a type of index, which locates the table rows and determines how to group the rows together in the table space.
Can you define concurrency?
More than one DB2 application process can access the same data at the same time, is known as concurrency. However, problems can happen such as, lost updates access to unrepeatable reads and uncommitted data.
Can you explain the Function done by data manager?
Data manager can be considered as a component that is capable of managing the databases that are physically present and is capable of invoking other components associated with the system for performing functionalities like logging, locking and in performing other I/O operations.
Can you explain DBRM?
DBRM stands for Database Request Module and is a component inside DB2, which is created by the pre compiler of DB2. This is a module that consists of SQL source statements that get extracted out of the application program. DBRMs form inputs that are helpful in the binding process.
Can you explain Data page?
Data page can be considered as a unit that is capable of retrieving data from the database. The database from which the data can be retrieved is in the form of 4 kilobytes or 32 kilobytes. The form in which data is retrieved depends on the way the table is defined inside the database. Data page also contains information regarding the catalog or user that is part of the database.
Can you explain correlated sub-queries?
Correlated sub-queries are those queries wherein the nester query on the inner side refers directly back to outer query’s table. For each and every row that is qualified, the evaluation of correlated sub-query is a must.
Explain Comment whether the cursor is closed during COMMIT or not?
Yes. The cursor is closed during COMMIT.
In an SQL table that is embedded, what is the procedure to retrieve rows that are part of a DB2 table?
Either you can use SELECT statements of single rows or an alternative way is to use CURSOR.
What is the highlighting as well as putting a CURSOR to use in a COBOL program?
The best way of putting a CURSOR to use in a COBOL program is to make use of DECLARE CURSOR, which can be used either in procedure division operation or in working storage. This is being done basically to highlight the SELECT statement.
Once DECLARE CURSOR is used, this is followed by OPEN, FETCH and finally CLOSE.
If the CURSOR is kept open followed the issuing of COMMIT, what is the procedure to leave the CURSOR that way?
Inside DECLARE CURSOR, there is a WITH HOLD option, which will come useful in this case. Although, one should note the point that WITH HOLD function has absolutely no effect if considered for CICS pseudo-conventional programs.
Can you define PACKAGES?
PACKAGES are units, which consist of executable codes that are meant for SQL statements for one respective DBRM.
What are the some the advantages that are attached to a PACKAGE?
Following are the advantages attached to a PACKAGE
- Avoid the cost of a large collection of bind. It is much more advisable to go for a small collection instead of a large one.
- Ensure that you do not have to bring a large collection of members of DBRM together for a particular plan.
- In case if you wish to make changes in the program and these changes eventually lead to errors, then you can decrease the fallback complexities with the help of PACKAGE.
- During the process of automatic binding and rebinding of a particular plan, make sure that the total transaction attached to the process is unavailable during the course.
What is the length of physical storage of the given data types of DB2 – DATE, TIMESTAMP, TIME?
DATE: PIC X (10)
TIMESTAMP: PIC X (26)
TIME: PIC X (08)
For a DB2 column that is being defined as DECIMAL (11, 2), discuss the COBOL picture clause”]
PIC S9 (9) V99 COMP – 3
In the expression DECIMAL (11, 2) 2 happens to be the precision whereas 11 is the data type size.
Can you define DCLGEN?
DCLGEN basically refers to DeCLarations GENerator whose primary purpose is to generate copy books of the host language for the tables. It is also used to create the DECLARE table.
What are the some fields that are a part of SQLCA?
SQLERRM, SQLCODE, SQLERRD.
Can you explain the contents that are a part of DCLGEN?
There are primarily two components of DCLGEN. These are:
- A copy book of the host language, which will give alternative definitions for all the column names.
- In terms of the data-types of DB2, EXEC SQL DECLARE TABLE shows an aesthetic layout of the table.
Can you explain comment whether DCLGEN is mandatorily used. If not, then what is the point of using it?
It is not exactly mandatory to bring DCLGEN into use. The primary use of DCLGEN comes during the pre-compilation phase where it helps in detecting the misspelt column names. Since DCLGEN is just a tool, it will only generate variable definitions for the host and reduces the chances of errors.
What are the two most DB2 interfaces?
Variety of ways to interface with DB2 is available, such as with programs using TSO, CAF, CICS, and so on.
Two of the most common interfaces provided with the DB2 product are DB2 Interactive (DB2I) and Sequential Processing Using File Input (SPUFI)
In case if at some point of time DB2 is down, would that impact the pre-compilation process of a DB2-COBOL program?
Even if DB2 is down at some point of time, even then it will not impact the pre-compilation process of DB2-COBOL program. The reason for the same is that the pre-compiler never refers to the catalogue tables of DB2.
Following a DB2 update statement, what is the quickest way to compute the total number of updated rows?
All you have to do is check the value that has been stored in SQLERRD (3).
What is the different address spaces used in DB2?
System Services Address Space (SSAS)
Database Services Address Space (DSAS)
Internal Resource Lock Manager (IRLM)
Distributed Database Facility (DDF)
STORED PROCEDURE ADDRESS SPACE (SPAS)
ALLIED ADDRESS SPACES
What is EXPLAIN in DB2?
EXPLAIN is basically used to show the path of access by the optimizer basically for an SQL statement. Furthermore, EXPLAIN can also be brought to use in SPUFI or even in BIND step.
What are the prerogatives, before you give the EXPLAIN statement,?
Before giving the EXPLAIN statement, we need to make sure that PLAN_TABLE has already been created under AUTHID.
What is a corelated subquerry?
In a subquerry, if the outer querry refers back to the outcome of innerquerry it is called corelated subquerry. That’s why the outer querry is evaluated first unlike an ordinary subquerry.
Can you explain Outputs of EXPLAIN are with MATCHCOLS = 0. What does this signify?
This signifies a non-matching scan of index provided that ACCESSTYPE = I
What is the location where the output received from EXPLAIN statement is stored
The output from EXPLAIN is stored in userid.PLAN_TABLE
Can you define RELEASE/ACQUIRE in BIND?
There is a certain point in a program at which DB2 acquires or perhaps releases the locks against tables as well as table-spaces. These include intent locks.
What a storage group (stogroup) is?
A STOGROUP is a named collection of DASD volumes to be used by tablespaces and index spaces of databases. The volumes of STOGROUP must be of the same device type.
What are the levels of isolation available with DB2v4?
CS RR UR( added new for DB2V4 which stands for uncommitted read which allows to retrieve records from the space which has exclusive locks also but data integrity will be affected if this option is used )The best available option for data integrity & data concurrency is CS.
How do you declare a host variable (in COBOL) for an attribute named EMP-name of type varchar (25)?
01 EMP-GRP. 49 E-LEN PIC S9 (4) COMP. 49 E-NAME PIC X (25)
What is the size of a data page?
What are the different locking levels that are available in DB2?
TABLE, PAGE and TABLESPACE
How you will count the number of rows from a table TAB?
SELECT COUNT (*) FROM TAB query is used to count the number of rows in a table.
What are the various locks that are available in DB2?
EXCLUSIVE, SHARE and UPDATE
What are the downsides of PAGE level lock?
In case if there are large updates to be done, then the resource utilization is high accordingly.
What are the different commands used in DB2?
The DSN command and its sub commands
- DB2 commands
- IMS commands
- CICS Attachment Facility Commands
- MVS IRLM commands
- TSO CLISTs
What is the difference between TYPE 1 index & TYPE 2 index?
TYPE 1 & TYPE 2 are specified when an index is created on the table. TYPE 2 index is the option which comes with DB2V4. With TYPE 2 index data can be retrieved faster as only the data pages are locked and not the index pages. Hence TYPE 2 index is recommended.