Top 100 IBM DB2 Interview Questions And Answers For Experienced. Here coding compiler presenting a list of real time db2 interview questions. This list includes, db2 dba interview questions and answers for experienced, db2 objective questions and answers, db2 queries examples.
DB2 Interview Questions
These db2 interview questions are prepared by the industry experts with clear explanation. We are sure that this post will help you to crack your next bd2 job interview. All the best for your future and happy learning.
DB2 Interview Questions And Answers
DB2 Interview Question 1) How would you find out the total number of rows in a DB2 table?
Use SELECT COUNT(*) … in db2 query
DB2 Interview Question 2) How do you eliminate duplicate values in DB2
SELECT ?
Use SELECT DISTINCT … in db2 query
DB2 Interview Question 3) How do you select a row using indexes in DB2?
Specify the indexed columns in the WHERE clause of
db2 query.
DB2 Interview Question 4) How do you find the maximum value in a column in db2?
Use SELECT MAX(…) .. in db2 query
DB2 Interview Question 5) How do you retrieve the first 5 characters of FIRSTNAME column of DB2 table EMP ?
SQL Query : SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;
DB2 Interview Question 6) What are aggregate functions?
Bulit-in mathematical functions for use in SELECT clause.
DB2 Interview Question 7) Can you use MAX on a CHAR column?
YES.
DB2 Interview Question 8) My SQL statement SELECT AVG(SALARY) FROM EMP yields inaccurate results. Why?
Because SALARY is not declared to have NULLs and the employees for whom the salary is not known are also counted.
DB2 Interview Question 9) How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?
SELECT FIRSTNAME || ‘ ‘ || LASTNAME FROM EMP;
DB2 Interview Question 10) What is the use of VALUE function?
1. Avoid -ve SQLCODEs by handling nulls and zeroes in computations
2. Substitute a numeric value for any nulls used in computation
DB2 Interview Question 11. When the LIKE statement is used?
LIKE statement is used to conduct partial searches like the search of employees by name. It is not necessary to indicate the complete name, the partial string matches would do.
DB2 Interview Question 12. 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 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.
DB2 Interview Question 13. What is a CURSOR and what is its use?A CURSOR is programming device that helps the SELECT to find out set of rows but displays them one at a time. Since the host language can deal with only one row at a time.
DB2 Interview Question 14. How to retrieve rows from a DB2 table in embedded SQL?
Rows form DB2 table embedded SQL can be retrieved using the single row SELECT statement. Another way is using the CURSOR. However, the first process is the preferred one.
DB2 Interview Question 15. What is the result of OPEN CURSOR statement?In simple OPEN CURSOR statement the CURSOR is placed on the first row of the table. On the other hand, if the ORDER BY clause is added, rows would be fetched, sorted and would be available for the FETCH statement.
DB2 Interview Question 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.
DB2 Interview Question 17. How would the VARCHAR column REMARKS defined?
The VARCHAR column remarks would be defined as follows.10 REMARKS.49 REMARKS-LEN PIC S9(4) USAGE COMP.49 REMARKS-TEXT PIC X(1920).
DB2 Interview Question 18. What is the physical storage length 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.
DB2 Interview Question 19. What is meant by DCLGEN?
DCLGEN refers to DeClarations GENerator that is used to create the host language copy books for the table definitions. It also creates the DECLARE table.
DB2 Interview Question 20. What are the contents of DCLGEN?
The contents of DCLGEN are EXEC SQL DECLARE TABLE statement that gives the layout of the table/view in terms of the DB2 data types. It can also be defined as the host language copy book giving host variable definitions for the column names.
DB2 Interview Questions 31) List Some Fields From Sqlca.?
SQLCODE, SQLERRM, SQLERRD
DB2 Interview Questions 32) Can You Tell Me How Can You Find Out The # Of Rows Updated After An Update Statement?
You need to check the value stored in SQLERRD(3)
DB2 Interview Questions 33) Can You Tell Where Is The Output Of Explain Stored?
In user id PLAN_TABLE
DB2 Interview Questions 34) What Does It Mean – Explain Has Output With Matchcols = 0?
A non matching index scan if ACCESSTYPE = I
DB2 Interview Questions 35) Explain How Can You Do The Explain Of A Dynamic Sql Statement?
Use SPUFI or MF to EXPLAIN the dynamic SQL statement
Include EXPLAIN command in the embedded dynamic SQL statements
DB2 Interview Questions 36) Explain What Are The Various Isolation Levels Possible ?
The isolation levels are CS: Cursor Stability RR: Repeatable Read
DB2 Interview Questions 37) Differentiate Between Cs And Rr Isolation Levels?where Do You Specify Them?
CS: Releases the lock on a page after use
RR: Retains all locks acquired till end of transaction. ISOLATION LEVEL is a parameter for the bind process
DB2 Interview Questions 38) When Do You Specify The Isolation Level?
During the BIND process ISOLATION ( CS/RR )
DB2 Interview Questions 39) Name The Various Locking Levels Available?
PAGE, TABLE, TABLESPACE
DB2 Interview Questions 40) Explain In Brief How Does Db2 Determine What Lock-size To Use?
Based on the lock-size given while creating the tablespace
Programmer can direct the DB2 what lock-size to use
If lock-size ANY is specified, DB2 usually choses a lock-size of PAGE
DB2 Interview Questions 41) How is a typical DB2 batch pgm executed ?
1. Use DSN utility to run a DB2 batch program from native TSO. An example is shown:
DSN SYSTEM(DSP3)
RUN PROGRAM(EDD470BD) PLAN(EDD470BD) LIB(‘ED 01T.OBJ.LOADLIB’)
END
2. Use IKJEFT01 utility program to run the above DSN command in a JCL.
Assuming that a site’s standard is that pgm name = plan name, what is the easiest way to find out which pgms are affected by change in a table’s structure ?
Query the catalogue tables SYSPLANDEP and SYSPACKDEP.
DB2 Interview Questions 42) Name some fields from SQLCA.
SQLCODE, SQLERRM, SQLERRD
DB2 Interview Questions 43) How can you quickly find out the # of rows updated after an update statement?
Check the value stored in SQLERRD(3).
DB2 Interview Questions 44) What is EXPLAIN?
EXPLAIN is used to display the access path as determined by the optimizer for a SQL statement. It can be used in SPUFI (for single SQL statement ) or in BIND step (for embedded SQL ).
DB2 Interview Questions 45) What do you need to do before you do EXPLAIN?
Make sure that the PLAN_TABLE is created under the AUTHID.
DB2 Interview Questions 46) Where is the output of EXPLAIN stored?
In userid.PLAN_TABLE
DB2 Interview Questions 47) EXPLAIN has output with MATCHCOLS = 0. What does it mean?
A nonmatching index scan if ACCESSTYPE = I.
DB2 Interview Questions 48) How do you do the EXPLAIN of a dynamic SQL statement?
1. Use SPUFI or QMF to EXPLAIN the dynamic SQL statement
2. Include EXPLAIN command in the embedded dynamic SQL statements
DB2 Interview Questions 49) 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 ). e.g.
SELECT EMP_NAME
FROM EMP
WHERE EMP_SALARY > ?
DB2 Interview Questions 50) What are the isolation levels possible ?
CS: Cursor Stability
RR: Repeatable Read
DB2 Interview Questions 51) What is the difference between CS and RR isolation levels?
CS: Releases the lock on a page after use
RR: Retains all locks acquired till end of transaction
DB2 Interview Questions 52) Where do you specify them ?
ISOLATION LEVEL is a parameter for the bind process.
DB2 Interview Questions 53) When do you specify the isolation level? How?
During the BIND process. ISOLATION ( CS/RR )…
I use CS and update a page. Will the lock be released after I am done with that page?
No.
DB2 Interview Questions 54) What are the various locking levels available?
PAGE, TABLE, TABLESPACE
DB2 Interview Questions 55) How does DB2 determine what lock-size to use?
1. Based on the lock-size given while creating the tablespace
2. Programmer can direct the DB2 what lock-size to use
3. If lock-size ANY is specified, DB2 usually chooses a lock-size of PAGE
DB2 Interview Questions 56) What are the disadvantages of PAGE level lock?
High resource utilization if large updates are to be done
DB2 Interview Questions 57) What is lock escalation?
Promoting a PAGE lock-size to table or tablespace lock-size when a transaction has acquired more locks than specified in NUMLKTS. Locks should be taken on objects in single tablespace for escalation to occur.
DB2 Interview Questions 58) What are the various locks available?
SHARE, EXCLUSIVE, UPDATE
DB2 Interview Questions 59) Can I use LOCK TABLE on a view?
No. To lock a view, take lock on the underlying tables.
DB2 Interview Questions 60) What is ALTER ?
SQL command used to change the definition of DB2 objects.
DB2 INTERVIEW QUESTIONS
DB2 Interview Questions 61) What is a DBRM, PLAN ?
DBRM: DataBase Request Module, has the SQL statements extracted from the host language program by the precompiler.
PLAN: A result of the BIND process. It has the executable code for the SQL statements in the DBRM.
DB2 Interview Questions 62) What is ACQUIRE/RELEASE in BIND?
Determine the point at which DB2 acquires or releases locks against table and tablespaces, including intent locks.
DB2 Interview Questions 63) 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
DB2 Interview Questions 64) 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.
DB2 Interview Questions 65) What are PACKAGES ?
They contain executable code for SQL statements for one DBRM.
DB2 Interview Questions 66) What are the advantages of using a PACKAGE?
1. Avoid having to bind a large number of DBRM members into a plan
2. Avoid cost of a large bind
3. Avoid the entire transaction being unavailable during bind and automatic rebind of a plan
4. Minimize fallback complexities if changes result in an error.
DB2 Interview Questions 67) 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.
In SPUFI suppose you want to select max. of 1000 rows , but the select returns only 200 rows.
DB2 Interview Questions 68) What are the 2 sqlcodes that are returned?
100 ( for successful completion of the query ), 0 (for successful COMMIT if AUTOCOMMIT is set to Yes).
DB2 Interview Questions 69) How would you print the output of an SQL statement from SPUFI?
Print the output dataset.
DB2 Interview Questions 70) How do you pull up a query which was previously saved in QMF ?
DB2 Interview Questions 71) Lot of updates have been done on a table due to which indexes have gone haywire. What do you do?
Looks like index page split has occurred. DO a REORG of the indexes.
DB2 Interview Questions 72) What is dynamic SQL?
Dynamic SQL is a SQL statement created at program execution time.
DB2 Interview Questions 73) When is the access path determined for dynamic SQL?
At run time, when the PREPARE statement is issued.
DB2 Interview Questions 74) Suppose I have a program which uses a dynamic SQL and it has been performing well till now. Off late, I find that the performance has deteriorated. What happened?
Probably RUN STATS is not done and the program is using a wrong index due to incorrect stats.
Probably RUNSTATS is done and optimizer has chosen a wrong access path based on the latest statistics.
DB2 Interview Questions 75) How does DB2 store NULL physically?
As an extra-byte prefix to the column value. physically, the nul prefix is Hex ’00’ if the value is present and Hex ‘FF’ if it is not.
DB2 Interview Questions 76) How do you retrieve the data from a nullable column?
Use null indicators. Syntax … INTO :HOSTVAR:NULLIND
DB2 Interview Questions 77) What is the picture clause of the null indicator variable?
S9(4) COMP.
DB2 Interview Questions 78) 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
DB2 Interview Questions 79) 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
DB2 Interview Questions 80) What is RUNSTATS?
A DB2 utility used to collect statistics about the data values 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.
DB2 Interview Questions 81) When will you chose to run RUNSTATS?
After a load, or after mass updates, inserts, deletes, or after REORG.
DB2 Interview Questions 82) Give some example of statistics collected during RUNSTATS?
# of rows in the table
Percent of rows in clustering sequence
# of distinct values of indexed column
# of rows moved to a nearby/farway page due to row length increase
DB2 Interview Questions 83) What is REORG? When is it used?
REORG reorganizes data on physical storage to reclutser rows, positioning overflowed rows in their proper sequence, to reclaim space, to restore free space. It is used after heavy updates, inserts and delete activity and
after segments of a segmented tablespace have become fragmented.
DB2 Interview Questions 84) What is IMAGECOPY ?
It is full backup of a DB2 table which can be used in recovery.
DB2 Interview Questions 85) When do you use the IMAGECOPY?
To take routine backup of tables
After a LOAD with LOG NO
After REORG with LOG NO
DB2 Interview Questions 86) What is COPY PENDING status?
A state in which, an image copy on a table needs to be taken, In this status, the table is available only for queries.
You cannot update this table. To remove the COPY PENDING status, you take an image copy or use REPAIR utility.
DB2 Interview Questions 87) What is CHECK PENDING ?
When a table is LOADed with ENFORCE NO option, then the table is left in CHECK PENDING status. It means that the LOAD utility did not perform constraint checking.
DB2 Interview Questions 88) What is QUIESCE?
A QUIESCE flushes all DB2 buffers on to the disk. This gives a correct snapshot of the database and should be used before and after any IMAGECOPY to maintain consistency.
DB2 Interview Questions 89) What is a clustering index ?
Causes the data rows to be stored in the order specified in the index. A mandatory index defined on a partitioned table space.
DB2 Interview Questions 90) How many clustering indexes can be defined for a table?
Only one.
DB2 Interview Questions 91) What is the difference between primary key & unique index ?
Primary : a relational database constraint. Primary key consists of one or more columns that uniquely identify a row in the table. For a normalized relation, there is one designated primary key.
Unique index: a physical object that stores only unique values. There can be one or more unique indexes on a table.
DB2 Interview Questions 92) What is sqlcode -922 ?
Authorization failure
DB2 Interview Questions 93) What is sqlcode -811?
SELECT statement has resulted in retrieval of more than one row.
DB2 Interview Questions 94) What does the sqlcode of -818 pertain to?
This is generated when the consistency tokens in the DBRM and the load module are different.
DB2 Interview Questions 95) Are views updateable ?
Not all of them. Some views are updateable e.g. single table view with all the fields or mandatory fields.
Examples of non-updateable views are views which are joins, views that contain aggregate functions(such as MIN), and views that have GROUP BY clause.
DB2 Interview Questions 96) If I have a view which is a join of two or more tables, can this view be updateable?
No.
DB2 Interview Questions 97) What are the 4 environments which can access DB2 ?
TSO, CICS, IMS and BATCH
DB2 Interview Questions 98) What is an inner join, and an outer join ?
Inner Join: combine information from two or more tables by comparing all values that meet the search criteria in the designated column or columns of on e table with all the clause in corresponding columns of the other table or
tables. This kind of join which involve a match in both columns are called inner joins.
Outer join is one in which you want both matching and non matching rows to be returned. DB2 has no specific operator for outer joins, it can be simulated by combining a join and a correlated sub query with a UNION.
DB2 Interview Questions 99) What is FREEPAGE and PCTFREE in TABLESPACE creation?
PCTFREE: percentage of each page to be left freeFREEPAGE: Number of pages to be loaded with data between each free page
DB2 Interview Questions 100) What are simple, segmented and partitioned table spaces ?
Simple Tablespace:
Can contain one or more tables
Rows from multiple tables can be interleaved on a page under the DBAs control and maintenance
Segmented Tablespace:
Can contain one or more tables
Tablespace is divided into segments of 4 to 64 pages in increments of 4 pages. Each segment is dedicated to single table. A table can occupy multiple segments
Partitioned Tablespace:
Can contain one table
Tablespace is divided into parts and each part is put in a separate VSAM dataset.
References: Mainframegurukul, Intellipaat, Tutorials Point, Wisdom Jobs.