IBM DB2 Interview Questions
IBM DB2 Interview Questions
Locking Services Component: This component is also known as the Internal Resource Lock
Manager. This component comes with the required controls to manage concurrent access to
Database Services Component: This component manages to define, update, and retrieve
users as well as system data. This component is prime in executing SQL statements and
management.
It is the substitute for a table or view. In other words, it is the alternative name of objects. The
objects can be tables, sequences, views, etc. An alias is usually defined as a local server. It can
also refer to a table or view at a remote server. We can use an alias if we want to refer to a table
or view in an SQL statement. Another thing is that we can create and drop aliases like we create
and drop tables and views.
5. What is a table space in DB2?
A tablespace is nothing but a set of volumes on disks. The disks contain the data sets where tables
are usually stored. A table space will have linear VSAM datasets. Tables are generally divided
into equal-sized units, known as pages. We can compress data in table spaces, which in turn saves
space and allows for storing more data. DB2 creates two types of table spaces such as partition by
growth and partition by range.
Structured Query Language (SQL) is nothing but the language used in DB2 to access data from
DB2. With this language, we can define and manipulate data in relational databases. We can
modify data objects such as tables. We can insert, delete, and update data in tables. Not only that,
we can use SQL to authorize users to access tables and views.
An attachment facility is an interface that connects DB2 with other environments. Here, the
environments can be WebSphere, Information Management System (IMS), Customer
Information Control System (CICS), Time Sharing Option (TSO), and Batch. We can use ODBC,
SQLJ, and JDBC interfaces to connect DB2 with other environments.
A Buffer pool is part of the main memory. You can store tables and indexes in a buffer pool.
Generally, the buffer pool is managed by the database manager.
Every DB2 has a buffer pool. Every new database comes with a buffer pool known as
IBMDEFAULTBP. You can create, drop or modify buffer pools with the help of the statements
such as CREATE BUFFERPOOL, ALTER BUFFERPOOL, and DROP buffer pool.
9. What are isolation levels, and name their types?
The isolation level in DB2 denotes the degree of isolation between the data and other concurrent
processes. There are four isolation levels in DB2: Repeatable Read (RR), Cursor Stability (CS),
Read Stability (RS), and Uncommitted Read (UR).
This is one of the isolation levels of IBM DB2. According to cursor stability, a row is locked
when the cursor is pointed at the row. Note that the specific row is accessed during a transaction,
and the lock remains locked until the transaction gets completed. Significantly, an application can
only update the row once the lock is released.
Usually, it is essential to declare tables and views when you write codes. The declarations
generator, or DCLGEN, generates DECLARE statements for programs written in C in addition to
COBOL. As a result, you can avoid writing codes for statements. Along with that, DCLGEN
generates respective host variable structures.
It is the process of releasing any number of page locks, LOB, row locks, and XML locks.
Applications on a single table or table space usually make these locks. Whenever a lock
escalation occurs in the database, it releases a message like DSNI0311. Using this message, we
can identify the tablespace where the lock escalation occurred.
The function receives a set of inputs but returns only a single value. In other words, the argument
of every aggregate function is a set of values.
ARRAY_AVG, COUNT, AVG, COUNT_BIG, MEDIAN, MAX (aggregate), and SUM are
some examples of aggregate functions.
SQLCA refers to SQL Communications Area. SQLCA is a set of variables updated at the end of
every SQL statement execution. There will be only one SQLCA for every application with
executable SQL statements. But at the same time, every multi-threaded application will have
more than one SQLCA.
The binding process uses DB2 as well as DBRM. Here, DBRM is nothing but a database request
module. During the binding process, the SQL statements in the DBRM switch to operational
mode. The binding process builds access paths to the DB2 table. Also, the binding process
supports authenticating users along with validating SQL statements in the DBRM.
You can insert data into a host variable to load the data into a table.
If you want to change the fields of rows in a table, you can use host variables.
While evaluating the WHERE as well as HAVING clauses, we can use the data in the host
variable.
If you want to indicate a NULL value, then you can use the host variable.
LOAD Authority
settings.
Instance level profile registry: This registry consists of all environment variable settings of
instances
Instance node-level profile registry: This registry has all the environment variable settings
User-level profile registry: This registry includes the environment variable settings that
belong to users.
19. What are the monitor elements in DB2, and brief them a bit?
Monitor elements are nothing but the data structures used to update the status of the DB2.
Following are a few examples of monitoring elements in DB2.
Counter: If any activity happens in DB2, counters record the number of times that activity
occurred.
Gauge: It represents the volume of activities that happen in DB2. For example, a gauge
Watermark: They are the highest values of various measurements taken against the activities
Text: They are the text values. For instance, stmt_text returns the text of SQL statements.
In its basic form, it is a rule that ensures data integrity in DB2. Only based on this rule, values are
allowed to store in one or more columns of a base table. This means that values are stored in a
base table after being verified by the check constraint. When you create a table in DB2, you can
also create the CHECK constraint.
The clustering index decides how the rows must be physically ordered in a table space. Know that
every table in DB2 comes with a clustering index. We can define clustering index on both
partitioned tablespaces as well as segmented table space. Also, Clustering indexes are highly
helpful in ordering operations, grouping operations, etc.
Two modes of security control are available in DB2, such as authentication and authorization.
Authentication is the security control used to allow users to access the DB2. It is managed by
external systems.
The authorization is the security control that allows users to access data within the DB2. A
database manager manages it.
Essentially, storage groups in DB2 represent a set of volumes on disks. This is where tables and
indexes are stored in datasets. Virtual Storage Access Method (VSAM) catalog stores the
datasets. With storage groups, DB2 defines, deletes, extends, and modifies VSAM datasets.
We can assign table spaces for storage groups. However, it is essential to note that table space is
usually associated with only one storage group, whereas one storage group may be associated
with many tablespaces.
26. What are the significant differences between Cursor Stability (CS) and
Repeated Read (RR) isolation levels?
CS offers good consistency and data integrity RR offers high-level data integrity due to its locki
27. Can you list out the advantages of using DB2 Packages?
DB2 physically stores the NULL value by adding an extra byte in prefix to the column value.
29. How can we retrieve rows from the DB2 table in Embedded SQL?
We can use the SELECT statement if we want to retrieve rows from the DB2 table. When more
than one row is returned, you can use the cursor to fetch a single row out of the multiple rows.
30. What are the two types of database logging used in DB2?
Circular logging: It is a default behavior when you create a new database.
Archive logging: It is used for roll-forward recovery. The log files are copied from the current
31. Can you differentiate INTEGER and SMALLINT data types in DB2?
INTEGER SMALLINT
It is used to store large binary integers with 31 bits It is used to store small binary integers with 15 bits
32. List out the advantages and disadvantages of INTEGER and SMALLINT
data types.
Advantages:
Both INTEGER and SMALLINT types need tiny spaces for values.
Using these data types, you can perform arithmetic and sorting operations such as SUM and
MAX.
Disadvantages:
They can store values only within a limit.
The database server cannot store values that exceed the capacity of integers.
33. Differentiate DELETE and DROP statements in DB2.
DELETE Statement DROP statement
It deletes a row from a table or
It removes an object or table from the database
view
Only the rows are deleted. No If an object is removed, the objects associated with the dropped object also
other associated entities are removed. It doesn’t matter whether they are associated directly or indirectl
deleted. object.
QMF stands for Query Management Facility SPUFI stands for SQL Processor Using File Inpu
There is no need that all the DB2 users should have QMF Every DB2 customer will have SPUFI, undoubte
It reduces the number of physical I/O operations with the help of advanced buffering
It contains one or more tables It contains one or more tables It contains only one table row
and stores rows for all tables
IMS, TSO, CICS, and BATCH are the four environments that can access DB2 seamlessly.
38. What is the use of DB2 optimizer, and how does it find the optimum
access plan?
DB2 optimizer processes every SQL statement and selects a query access plan. It estimates the
execution costs of multiple access plans and selects the access plan with the minimum cost.
When selecting the optimum access plan, the DB optimizer achieves it in the following way.
It identifies the columns that must be returned and the columns in the predicate
quick scanning.
They are physically clustered with more than one key or dimension
MDC tables can maintain their clustering over all dimensions automatically as well as
continuously
You can easily share data with DB2. This is because it comes with AI capabilities that simplify
DB2 has compression capabilities with which you can save space significantly without
compromising performance
Cons:
DB2 responds slowly when the file size is large
It is essential to note that the result of this function will be an integer. And it cannot be a null
value.
The argument of the COUNT (*) function is a set of rows. This function returns the number of
rows in a set of rows.
The argument of the COUNT (expression) function is a set of values. This function will return
the number of non-null values in the set. Note that this function includes duplicate values for
counting.
The argument of the COUNT (DISTINCT expression) function is a set of values. This function
will return the number of non-null values in the set. Note that this function removes duplicate
values.
42. How can you move a table space to another DASD volume?
We can move the table space by using ALTER STOGROUP statement. This is possible only
when the tablespace is allocated to that storage group.
When there is a program abend, DB2 performs the auto rollback function.
If we change the structure of a table, then we need to change the program. The change can be
adding or deleting a field in the table.
Sometimes, it leads to I/O overhead due to the retrieval of columns that is not required for the
users.
45. Why do you need to create MQT, and how will you create it?
We create Materialized Query Table (MQT) to improve the performance of SQL applications.
46. Can you eliminate duplicate values from a table in DB2? If yes, how
will you do this?
Yes. We can remove many identical rows from the result table of a query. You need to use the
DISTINCT keyword in the query to achieve this. This is because the DISTINCT keyword
eliminates the duplicate rows from the query result table. As a result, every result table will
contain only the unique data.
47. If you drop the index of a PLAN, what would be the response?
If this case, it will impact PLANS negatively. The PLANS may contain the SQLs using that
dropped index. Simply put, the PLAN will be marked as invalid.
Know that locks are essential to achieve concurrency in DB2. Timeout, Suspension, and
Deadlock are the contention situations created by locks. And they will degrade the performance
of DB2, undoubtedly.
Suspension: This situation occurs when an application requests a lock already held by
another. The requested application must stop its operation until the application releases the
lock. The application resumes its operation only when the lock is released.
Timeout: This situation occurs when the suspension of an application exceeds the defined
preset level. In that case, DB2 terminates the application and returns error codes.
Deadlock: This situation occurs when two or more applications lock specific resources and
not allows other applications to access the resources. The main thing is that the other
applications can only proceed with their operations if they access the locked resources.
50. What is the maximum number of volumes that you can add in a
STOGROUP?
To find the number of rows in a DB2 table, the user has to use SELECT COUNT (*) on the DB2
query
To eliminate the duplicate values from DB2 SELECT, the user has to use SELECT DISTINCT in
the DB2 query.
‘Aggregate’ functions are built-in mathematical tools that are used in the DB2 SELECT clause.
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 are also eliminated.
The LIKE statement is used to conduct partial searches such as the search of employees by name.
It is not necessary to indicate the complete name, partial string matches would do.
We can perform two tasks using the ‘value’ function:First, to avoid -ve SQLCODEs by handling
NULLs and 0s in the computation. Second, to substitute numeric values for NULLs used in the
computation
Both UNION and UNION ALL are used to combine the results generated by multiple SELECT
statements. UNION is the function that eliminates duplicates in the table. UNION ALL retains
the duplicates
10. What do you mean by BETWEEN and IN? Is BETWEEN inclusive of specified range
values?
BETWEEN would supply a range of values, whereas IN would provide a list of values.
BETWEEN is always inclusive of the range values specified.
11. How can the FIRSTNAME and the LASTNAME from the EMP table be concatenated to
generate complete names?
The statement that can be used to concatenate the first and last names to display full
names:FIRSTNAME II ** II LASTNAME FROM EMP
12. What could be the reason that the MySQL statement 'SELECT AVG (SALARY) FROM
EMP' generates an inaccurate output?
The reason for the statement generating an inaccurate outcome is that SALARY has not been
declared to have NULL values and, at the same time, the employees whose salary is not known
are also counted.
A CURSOR is a programming device that helps the SELECT statement find out a set of rows but
displays them one at a time. This is because the host language can deal with only one row at a
time.
Rows from a DB2 table in Embedded SQL can be retrieved using the single-row SELECT
statement. Another way is by using the CURSOR statement. However, the first process is the
preferred one.
In the simple OPEN CURSOR statement, the CURSOR is placed on the first row of a table. On
the other hand, when the ORDER BY clause is added, rows would be fetched, sorted, and would
be available for the FETCH statement.
16. Can there be more than one cursor open for any program?
Yes! The user can have more than one cursor open for any program.
18. What is the physical storage length of each of the data types, DATE, TIME, and
TIMESTAMP?
The physical storage length of DATE is 4 bytes, TIME is 3 bytes, and TIMESTAMP is 10 bytes.
DCLGEN has the EXEC SQL DECLARE TABLE statement that gives the layout of a table/view
in terms of DB2 data types. It can also be defined as the host language copy book giving the host
variable definitions for column names.
EXPLAIN is used for displaying the access path as determined by the optimizer for SQL
statements. It can also be used in the case of SPUFI for single SQL statements or in the BIND
step for Embedded SQL.
Users can use SPUFI or QMF statements to perform EXPLAIN for Dynamic SQL statements.
They can also include the EXPLAIN command in the Embedded Dynamic SQL statements.
Two isolation levels are possible: One is Cursor Stability and the other is Repeatable Read
denoted as CS and RR, respectively.
CS would release the lock on the page after its use. RR would retain all the locks acquired till the
end of a transaction.
Lock escalation is the process of promoting page lock sizes to table or table space lock size when
the transaction has acquired more locks than the ones specified in NUMLKTS. Locks have to be
taken on objects in a single table space for escalations to take place.
27. What are the various types of Locks?
here are three different types of locks: SHARE, EXCLUSIVE, and UPDATE.
ALTER is the SQL command used to change the definition of DB2 objects.
DBRM denotes Database Request Module. It has the SQL statements that are extracted from the
host language program obtained by the pre-compiler; PLAN is the result of the BIND process and
has executable code for SQL statements in DBRM.
ACQUIRE/RELEASE in BIND determines the point at which DB2 either acquires or releases
locks against the table and the table spaces. This includes the intent locks.
PACKAGES contain executable codes for SQL statements in respect of one DBRM.
When used, PACKAGES help avoid binding of large numbers of DBRM members in one plan.
They also dispense with the cost of large BIND and avoid the entire transactions making them
unavailable during BIND and automatic REBIND of the plan. Another advantage is that they
minimize the fallback complexities when changes result in an error.
A collection is a user-defined name that works as the anchor for packages but has no physical
existence. It is used for the grouping of packages.
Dynamic SQL is the SQL statement created at the time of the execution of a program.
Locking services are provided by Locking services component which is known as Internal
Resource Lock Manager (IRLM) and manages concurrency issues and dead locks.
Database services component is responsible for execution of SQL statements and it manages
buffer pool also.
Locking can be applied on either of these - Page, table and table space.
In Bind step we specify the isolation level. 41. Which field in SQLCA shows the number of
updated rows after update statement?
Check the value of SQLERRD to know how many rows got updated after an update statement.
44. Which component is used to processes SQL statements and selects the access paths?
DB2 optimizer is used to select the access paths & to process the SQL queries.
45. In a COBOL-DB2 program all SQL statements must be coded in Area A. State whether true
or false?
46. Cursors are used to handle single row selections at a time. They are data structure which hold
all the results of a query. State whether true or false?
This statement is incorrect as cursors are used to handle multiple row selections at a time.
47. Host variables cannot be group items but they may be grouped together in host structure.
They can be Renamed or Redefined. State whether true or false?
48. When a table is dropped all the alias get dropped automatically. State whether true or false?
This statement is incorrect. Synonyms get dropped automatically when we drop the table but alias
of the table remains there. We need to manually drop the alias.
When a program abends in middle of some transaction then DB2 performs a auto rollback.
50. If a transaction takes a Update lock on some data, then other transactions can get what type of
lock?
If a transaction takes an Update lock on some data, then other transactions can only get only
Shared lock on it.