Q1
Explain the difference between INNER JOIN and LEFT OUTER JOIN.
INNER JOIN:
- Returns only matching rows from both tables
- If no match, row is excluded
LEFT OUTER JOIN:
- Returns all rows from left table
- Matching rows from right table
- NULL for right table if no match
-- INNER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID; -- LEFT OUTER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E LEFT OUTER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID;
Use LEFT JOIN when you want all employees even those without department.
Q2
What is EXPLAIN and how to use it?
EXPLAIN analyzes query access path. Results in PLAN_TABLE. Shows index usage, join method, sort operations. Review ACCESSTYPE, MATCHCOLS for tuning.
Q3
What causes -811 SQLCODE?
SELECT INTO returned multiple rows when expecting one. Solutions: Add WHERE for single row, use MAX/MIN, declare cursor for multiple rows.
Q4
Explain DB2 isolation levels.
UR: Uncommitted read (dirty read OK). CS: Cursor stability (current row locked). RS: Read stability (accessed rows locked). RR: Repeatable read (range locked, no phantom).
Q5
What is RUNSTATS and when to run it?
RUNSTATS collects statistics for optimizer. Run after significant data changes. Updates SYSTABLES, SYSINDEXES. Critical for optimal access path selection.
Q6
What is DB2 plan vs package?
Plan is bound executable SQL. Package is independent SQL unit. Modern approach: packages in collections with small plans. Packages allow separate rebind.
Q7
Explain -911 SQLCODE handling.
Deadlock or timeout. Two processes waiting for each other. Solutions: Retry transaction, consistent lock order, shorter transactions, appropriate isolation level.
Q8
What is REBIND and when needed?
REBIND updates access path without precompile. After RUNSTATS, index changes, performance issues. Can improve or degrade - test first.
Q9
Explain buffer pool importance.
Buffer pool caches data/index pages. Hit ratio critical. GETPAGE vs SYNCIO shows effectiveness. Size appropriately for workload.