IT Software (34) 

Welcome to our DB2 Interview Questions and Answers Page

We are excited to have you here! Whether you are preparing for an interview or simply expanding your knowledge, this page is filled with valuable information and insights about DB2. Explore our comprehensive collection of questions and answers to enhance your understanding of this powerful database management system.

Top 20 Basic DB2 interview questions and answers

1. What is DB2 and its primary functions?
DB2 is a Relational Database Management System (RDBMS) that is designed to store, manage, and retrieve data efficiently. Its primary functions include data storage, data manipulation, and data retrieval.

2. What are the different components of DB2?
The different components of DB2 include Database Manager, Database system catalog, Data Tablespace, Index Tablespace, Buffer Pool, and Locking Services.

3. What is a tablespace?
A tablespace is a logical storage unit within a database where tables and indexes are stored. It is used to manage and allocate storage space for database objects.

4. What is an index in DB2?
An index in DB2 is a data structure that helps in efficient data retrieval. It is created on one or more columns of a table and allows for faster access to data based on the values in those columns.

5. What is a primary key?
A primary key is a column or combination of columns that uniquely identifies each row in a table. It enforces data integrity by ensuring that no duplicate or null values are allowed.

6. What is a foreign key?
A foreign key is a column or combination of columns in one table that refers to the primary key in another table. It establishes a relationship between the two tables and ensures data integrity.

7. What is meant by referential integrity?
Referential integrity ensures that relationships between tables are maintained correctly. It prevents actions that would leave foreign key values without a corresponding primary key value.

8. What is a stored procedure?
A stored procedure is a collection of SQL statements that are stored in the database and can be executed as a single unit. It allows for code reusability, improves performance, and provides increased security.

9. What is a trigger?
A trigger is a set of SQL statements that are automatically executed when a specified event occurs. It can be used to enforce business rules, maintain integrity, and perform complex calculations.

10. What is an isolation level?
Isolation level defines the degree to which transactions are isolated from each other. It determines how concurrent transactions interact and deal with data consistency and concurrency control.

11. What is a deadlock?
A deadlock occurs when two or more transactions are waiting for each other to release resources, resulting in a stalemate. It can lead to a situation where no progress can be made, and the transactions are blocked indefinitely.

12. What is a database lock?
A database lock is a mechanism used by DB2 to control concurrent access to data. It ensures that only one transaction at a time can modify or access a particular data item to maintain data consistency.

13. What is a commit and rollback?
A commit is an operation that makes the changes performed within a transaction permanent. It saves the changes to the database and releases any locks held by the transaction.
A rollback, on the other hand, is an operation that undoes all the changes made within a transaction. It restores the database state to the point just before the transaction started.

14. What is the difference between DELETE and TRUNCATE?
DELETE is a DML statement that removes specific rows from a table based on a condition. It can be rolled back if executed within a transaction.
TRUNCATE is a DDL statement that removes all the rows from a table in a single operation. It cannot be rolled back and is faster than DELETE as it does not generate individual undo records.

15. What is a check constraint?
A check constraint is a rule defined on a column or table that restricts the values allowed for the column. It ensures that only valid data is inserted or updated in the table, based on a condition defined by the constraint.

16. What is the difference between a view and a table?
A view is a virtual table derived from the data stored in one or more tables. It does not store any data itself but allows for a customized representation of the data.
A table, on the other hand, stores data physically in the database and is the primary entity for data storage and retrieval.

17. What is a buffer pool?
A buffer pool is an area of memory in DB2 used to cache frequently used table and index data. It helps in reducing disk I/O and improving overall query performance.

18. What is an alias in DB2?
An alias in DB2 is an alternate name given to a table, view, or column. It provides an additional level of abstraction and allows for easier referencing of database objects.

19. What is the EXPLAIN statement in DB2?
The EXPLAIN statement in DB2 is used to obtain information about the access path chosen by the optimizer for a specific SQL statement. It provides insights into how the statement will be executed and helps in query optimization.

20. What is a cursor?
A cursor is a database object used to retrieve and manipulate rows from a result set returned by a query. It allows for sequential processing of the retrieved data one row at a time.

Top 20 Advanced DB2 interview questions and answers

1. What is a correlated subquery in DB2?
A correlated subquery is a subquery that references one or more columns from the outer query. The subquery is evaluated once for each row processed by the outer query.

2. What is the difference between UNION and UNION ALL in DB2?
UNION combines the result sets of two or more SELECT statements, removing duplicate rows. UNION ALL, on the other hand, combines the result sets without removing duplicates.

3. What is an identity column in DB2?
An identity column is a column whose value is automatically generated by the system. It is typically used as a primary key column.

4. What is the purpose of isolation levels in DB2?
Isolation levels determine how concurrent transactions are allowed to interact with each other. They ensure data integrity and control access to data during concurrent operations.

5. How can you handle errors or exceptions in DB2?
Errors and exceptions in DB2 can be handled using the SQLCA (Structured Query Language Communication Area) or the SQLCODE (SQL return code) and SQLSTATE (SQL state code) variables.

6. What is a materialized query table (MQT) in DB2?
A materialized query table is a data structure that stores the result of a query for faster access. It is a physical table that can be used to improve query performance.

7. How can you retrieve the current timestamp in DB2?
The current timestamp in DB2 can be retrieved using the CURRENT TIMESTAMP special register.

8. What is the purpose of the EXPLAIN statement in DB2?
The EXPLAIN statement in DB2 is used to generate an access plan for a SQL statement without executing it. It helps in analyzing the performance and efficiency of a query.

9. What are the advantages of using stored procedures in DB2?
Stored procedures in DB2 offer several benefits, such as improved performance by reducing network traffic, better security by encapsulating logic, and code reusability.

10. How do you execute a stored procedure in DB2?
A stored procedure in DB2 can be executed using the CALL statement followed by the procedure name and any required parameters.

11. What is the purpose of the SYSCOLUMNS table in DB2?
The SYSCOLUMNS table in DB2 contains information about the columns of tables in a database, such as column names, data types, lengths, and position within the table.

12. What is the difference between a primary key and a unique constraint in DB2?
A primary key is a column or set of columns that uniquely identifies a row in a table and prevents duplicate entries. A unique constraint, on the other hand, allows only unique values in a column or set of columns but does not enforce the uniqueness across the entire table.

13. What is the purpose of the RUNSTATS command in DB2?
The RUNSTATS command in DB2 collects statistics about the data and indexes in a table, which the query optimizer uses to generate efficient access plans.

14. What is SQLCODE -811 in DB2?
SQLCODE -811 in DB2 indicates a duplicate key violation error. It occurs when an INSERT or UPDATE statement tries to add or modify a row with a key value that already exists in the table.

15. How can you monitor and optimize the performance of DB2 queries?
The performance of DB2 queries can be monitored and optimized using tools such as Explain, Visual Explain, and the Event Monitor. These tools help in identifying performance bottlenecks and suggesting improvements.

16. What is the purpose of the DB2 catalog?
The DB2 catalog is a set of system tables and views that store metadata about the database objects (tables, views, indexes, etc.) and their relationships. It is used by DB2 to manage and access the database.

17. What is dynamic SQL in DB2?
Dynamic SQL in DB2 allows the construction and execution of SQL statements at runtime. It offers flexibility by allowing the SQL statements to be built based on runtime conditions or user inputs.

18. How do you perform backup and recovery in DB2?
Backup and recovery in DB2 can be performed using the BACKUP and RESTORE commands. BACKUP creates a copy of the database or tablespace, while RESTORE restores the database or tablespace from a backup.

19. What are the different join types in DB2?
DB2 supports several join types, including inner join, outer join (left, right, and full), and cross join. Each join type specifies how data from multiple tables is combined.

20. What is the purpose of the LOCK TABLE statement in DB2?
The LOCK TABLE statement in DB2 is used to lock a table, restricting other transactions from modifying the table until the lock is released. It ensures data integrity and concurrency control.

IT Software (34) 

Interview Questions and answers

Filter:AllUnanswered
What are the different isolation levels supported by DB2?
suresh answered 6 months ago • 
43 views1 answers0 votes
What are the benefits and limitations of using tablespaces in DB2?
suresh answered 6 months ago • 
40 views1 answers0 votes
What is the difference between LOCKTABLE and LOCK TABLE in DB2?
suresh answered 6 months ago • 
52 views1 answers0 votes
What is the difference between VARCHAR and CHAR datatypes in DB2?
suresh answered 6 months ago • 
66 views1 answers0 votes
What is the difference between DB2 LUW and DB2 z/OS?
suresh answered 6 months ago • 
68 views1 answers0 votes
What is the difference between DB2 OLTP and DB2 Data Warehouse?
suresh answered 6 months ago • 
54 views1 answers0 votes
What is the difference between a primary key and a unique key in DB2?
suresh answered 6 months ago • 
65 views1 answers0 votes
What is a primary key in DB2 and why is it important?
suresh answered 6 months ago • 
78 views1 answers0 votes
What is the difference between primary key and unique key in DB2?
suresh answered 6 months ago • 
59 views1 answers0 votes
What is the difference between a table space and a buffer pool in DB2?
suresh answered 6 months ago • 
61 views1 answers0 votes
What is the difference between VARCHAR and CHAR data types in DB2?
suresh answered 6 months ago • 
59 views1 answers0 votes
What is the difference between COBOL-DB2 and PL/1-DB2?
suresh answered 6 months ago • 
108 views1 answers0 votes
What is the difference between a cursor and a result set in DB2?
suresh answered 6 months ago • 
55 views1 answers0 votes