This DB2 Interview Questions blog has a list of all the most important DB2 questions that you may encounter during the interview. Here, you will come across both basic and advanced-level concepts and questions related to these concepts. Moreover, from this DB2 Interview Questions blog, you will get a better knowledge and understanding of DB2. So, excel in your career by preparing the following DB2 interview questions:
Q1. How to find the number of rows in a DB2 table?
Q2. How can the duplicate values be eliminated from DB2 SELECT?
Q3. What is Aggregate?
Q4. Is it possible using MAX on a CHAR column?
Q5. Why SELECT is not preferred in Embedded SQL programs?
Q6. When is the LIKE statement used?
Q7. How is the value function used?
Q8. What are UNION and UNION ALL?
Q9. Is there any restriction on the use of UNION in Embedded SQL?
Q10. What do you mean by BETWEEN and IN? Is BETWEEN inclusive of specified range values?
The DB2 interview questions provided in this blog are divided into the parts mentioned below:
Watch Intellipaat’s video on SQL Full Course:
Basic Interview Questions
1. How to find the number of rows in a DB2 table?
To find the number of rows in a DB2 table, the user has to use SELECT COUNT (*) on the DB2 query.
2. How can the duplicate values be eliminated from DB2 SELECT?
To eliminate the duplicate values from DB2 SELECT, the user has to use SELECT DISTINCT in the DB2 query.
3. What is Aggregate?
‘Aggregate’ functions are built-in mathematical tools that are used in the DB2 SELECT clause.
4. Is it possible using MAX on a CHAR column?
Yes! It is possible using MAX on a CHAR column.
5. 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 are also eliminated.
Learn all about SQL Developers through this SQL Developer and SQL DBA Training Master’s Program!
6. When is the LIKE statement used?
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.
7. How is the value function used?
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
Get 100% Hike!
Master Most in Demand Skills Now !
8. What are UNION and UNION ALL?
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
9. Is there any restriction on the use of UNION in Embedded SQL?
While using UNION in Embedded SQL, it has to be in a CURSOR.
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.
Intermediate Interview Questions
11. How can the FIRSTNAME and the LASTNAME from the EMP table be concatenated to generate complete names?
Below is 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.
13. What is a CURSOR and what is its use?
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.
14. How to retrieve rows from a DB2 table in Embedded SQL?
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.
15. What is the result of the OPEN CURSOR statement?
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.
Now that you are aware of the benefits of SQL, enroll in our SQL Course today and excel in your career!
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.
17. How would the VARCHAR column REMARKS be 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)
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.
19. What is meant by DCLGEN?
DCLGEN refers to Declaration Generator that is used to create the host language copy books for the table definitions. It also creates the DECLARE table.
20. What are the contents of DCLGEN?
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.
If you have any doubts or queries related to SQL, get them clarified from our SQL experts on Intellipaat’s SQL Community!
Advanced Interview Questions
21. What are some of the main fields in SQLCA?
Major fields in SQLCA are SQLCODE, SQLERRM, and SQLERRD.
22. What is meant by EXPLAIN?
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.
23. How to perform EXPLAIN for any Dynamic SQL statement?
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.
24. What are the isolation levels possible?
Two isolation levels are possible: One is Cursor Stability and the other is Repeatable Read denoted as CS and RR, respectively.
25. What is the difference between CS and RR isolation levels?
CS would release the lock on the page after its use. RR would retain all the locks acquired till the end of a transaction.
26. What is meant by Lock Escalation?
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.
Learn more about SQL from this insightful SQL Tutorial!
27. What are the various types of Locks?
There are three different types of locks: SHARE, EXCLUSIVE, and UPDATE.
28. What is ALTER?
ALTER is the SQL command used to change the definition of DB2 objects.
29. What do you understand by DBRM and PLAN?
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.
30. What is meant by ACQUIRE/RELEASE in BIND?
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.
31. What is meant by PACKAGES?
PACKAGES contain executable codes for SQL statements in respect of one DBRM.
Wish to get SQL Server Certified? Read on SQL Server Certification!
32. What are the advantages of using PACKAGES?
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.
33. What is a collection?
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.
34. What is Dynamic SQL?
Dynamic SQL is the SQL statement created at the time of the execution of a program.