DB2 Interview Questions 2
- Explain an outer join.
Answer: An outer join includes rows from tables when there are no matching values in the tables.
- What is a subselect? Is it different from a nested select?
Answer: A subselect is a select which works in conjunction with another select.
A nested select is a kind of subselect where the inner select passes to the where criteria for the outer select.
- What is the difference between group by and order by?
Answer: Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement.
- Explain the EXPLAIN statement.
Answer: The explain statement provides information about the optimizer's choice of access path of the SQL.
- What is tablespace?
Answer: Tables are stored in tablespaces (hence the name). There are three types of tablespaces:
- segmented and
- What is a cursor and what is its function?
Answer: An embedded sql statement may return a number of rows while the programming language can only access one row at a time.
The programming device called a cursor controls the position of the row.
- What is referential integrity?
Answer: Referential integrity refers to the consistency that must be maintained between primary and foreign keys, for example, every foreign key value must have a corresponding primary key value.
- Usually, which is more important for DB2 system performance - CPU processing or I/O access?
Answer: I/O operations are usually most critical for DB2 performance (or any other database for that matter).
- Is there any advantage to denormalizing DB2 tables?
Answer: Denormalizing DB2 tables reduces the need for processing intensive relational joins and reduces the number of foreign keys.
- What is the database descriptor?
Answer: The database descriptor, DBD is the DB2 component that limits access to the database whenever objects are created, altered or dropped.
Using a Nested Table Expression as the right operand of a join
Example of using a nested table expression as the right operand of a join:
The following query contains a fullselect (in bold) as the right operand of a left outer join with the PROJECTS table.
The correlation name is TEMP. In this case the unmatched rows from the PROJECTS table are included, but the unmatched rows from the nested table expression are not.
SELECT PROJECT, COALESCE(PROJECTS.PROD#, PRODNUM) AS PRODNUM,
PRODUCT, PART, UNITS
FROM PROJECTS LEFT JOIN
COALESCE(PARTS.PROD#, PRODUCTS.PROD#) AS PRODNUM,
FROM PARTS FULL OUTER JOIN PRODUCTS
ON PARTS.PROD# = PRODUCTS.PROD#) AS TEMP
ON PROJECTS.PROD# = PRODNUM;
Nested Table Expression as the left operand of a join
Example of using a nested table expression as the left operand of a join:
The following query contains a fullselect as the left operand of a left outer join with the PRODUCTS table.
The correlation name is PARTX. In this case the unmatched rows from the nested table expression are included, but the unmatched rows from the PRODUCTS table are not.
SELECT PART, SUPPLIER, PRODNUM, PRODUCT
FROM (SELECT PART, PROD# AS PRODNUM, SUPPLIER
WHERE PROD# < '200') AS PARTX
LEFT OUTER JOIN PRODUCTS
ON PRODNUM = PROD#;
The result table looks similar to the following output:
PART SUPPLIER PRODNUM PRODUCT
======= ============ ======= ==========
WIRE ACWF 10 GENERATOR
MAGNETS BATEMAN 10 GENERATOR
OIL WESTERN_CHEM 160 ----------