👁 0
Q: What is index-only access?
Answer:
Index-only access retrieves data from index without table access. All needed columns in index (including by include clause). Best performance. EXPLAIN shows INDEXONLY=Y. Design indexes for common queries.
👁 0
Q: What is identity column?
Answer:
Identity column auto-generates values. col INTEGER GENERATED ALWAYS AS IDENTITY. Or GENERATED BY DEFAULT (allows override). Start, increment configurable. Alternative to sequence for single-table keys.
👁 0
Q: How to alter table structure?
Answer:
ALTER TABLE name ADD COLUMN col type. ALTER TABLE name DROP COLUMN col. ALTER TABLE name ALTER COLUMN col SET DATA TYPE. Some changes need REORG. Adding columns easy; changes may need unload/reload.
👁 0
Q: What is XML support in DB2?
Answer:
DB2 stores XML natively. XMLTYPE column. XMLPARSE, XMLSERIALIZE for conversion. XQuery for querying. XMLTABLE extracts relational from XML. XML indexes for performance. Powerful for document storage.
👁 0
Q: How to use EXPLAIN tables?
Answer:
PLAN_TABLE primary output. DSN_STATEMNT_TABLE for cost. DSN_FUNCTION_TABLE for functions. INSERT EXPLAIN before statement. Query tables after. PLANNO, ACCESSTYPE, MATCHCOLS important columns.
👁 0
Q: What is DB2 catalog?
Answer:
Catalog tables describe DB2 objects. SYSIBM.SYSTABLES for tables, SYSIBM.SYSCOLUMNS for columns, SYSIBM.SYSINDEXES for indexes. Query catalog for metadata. Read-only except through DDL. Essential for documentation and analysis.
👁 0
Q: What is indicator variable?
Answer:
Indicator variable detects NULL values. Declare: 01 col-var. 01 col-ind PIC S9(4) COMP. Use: INTO :col-var:col-ind. If col-ind < 0, value is NULL. Set indicator negative to insert NULL. Required for nullable columns.
👁 0
Q: How to use UNION?
Answer:
UNION combines SELECT results. UNION removes duplicates, UNION ALL keeps all. Column count and types must match. ORDER BY at end only. UNION expensive due to sort. Use UNION ALL if duplicates OK or impossible.
👁 0
Q: What is DISTINCT keyword?
Answer:
DISTINCT eliminates duplicate rows. SELECT DISTINCT col FROM table. Applies to entire row, not single column. Causes sort for duplicate elimination. Performance impact. Avoid if possible. Sometimes indicates bad design.
👁 0
Q: Explain CREATE INDEX
Answer:
CREATE INDEX creates index on table. CREATE INDEX idx ON table(col1, col2). UNIQUE prevents duplicates. CLUSTER determines physical order. Include columns for index-only access. Drop unused indexes for insert performance.
👁 0
Q: What is INSERT...SELECT?
Answer:
INSERT INTO table SELECT cols FROM other_table WHERE condition. Bulk insert from query. Column count/types must match. Faster than row-by-row. Can transform data during insert. Good for data migration.
👁 0
Q: Explain DB2 triggers
Answer:
Trigger fires automatically on INSERT/UPDATE/DELETE. CREATE TRIGGER name AFTER/BEFORE/INSTEAD OF event ON table FOR EACH ROW/STATEMENT. Use for audit, validation, derived columns. Can impact performance.
👁 0
Q: What is EXPLAIN and how to use it?
Answer:
EXPLAIN analyzes query access path. EXPLAIN PLAN SET QUERYNO=1 FOR SELECT... Results in PLAN_TABLE. Shows index usage, join method, sort operations. Use for performance tuning. Review ACCESSTYPE, MATCHCOLS, PREFETCH columns.
👁 0
Q: What is GROUP BY clause?
Answer:
GROUP BY aggregates rows. SELECT col, COUNT(*) FROM t GROUP BY col. All non-aggregate SELECT columns must be in GROUP BY. HAVING filters groups (vs WHERE filters rows). GROUP BY ROLLUP/CUBE for subtotals.
👁 0
Q: Explain ORDER BY options
Answer:
ORDER BY sorts results. ORDER BY col1 ASC, col2 DESC. ASC default. NULLS FIRST/LAST controls NULL position. Ordinal: ORDER BY 1, 2 uses column positions. ORDER BY CASE for custom order. Affects performance.