DB2 interview questions and answers for developers and DBAs
DB2 interview questions (IBM now styles the product Db2) test whether you can write and tune SQL that runs inside COBOL or Java programs: host variables and indicator variables, cursors, SQLCODEs such as +100, -803, -811 and -911, the precompile and BIND steps that create packages, isolation levels from UR to RR, and reading EXPLAIN output. DBA-leaning rounds add RUNSTATS, REORG, LOAD, backup and recovery. Know which platform the role uses, z/OS or Linux, UNIX and Windows.
By Evin JohnPublished 8 min read
Where DB2 questions come up
Db2 questions show up in two quite different worlds. On the mainframe, Db2 for z/OS sits behind COBOL batch and CICS transactions, so developer interviews focus on embedded SQL, SQLCODEs and binds, and support rounds on locks and abends; see COBOL interview questions and CICS interview questions. On distributed systems, Db2 for Linux, UNIX and Windows (LUW) behaves more like other relational servers, with instance and database administration, HADR and command-line tools. Standard SQL questions overlap with SQL interview questions; this page covers what is specific to Db2.
- SQL and SQLCODEsWrite a query, explain what a given SQLCODE means, and say what the program should do about it.
- Program interfaceCursors, host variables, nulls and commits in a COBOL or Java program, and how the program gets bound.
- PerformanceRead an EXPLAIN result, pick an index, explain why the access path changed after statistics or a rebind.
- OperationsUtilities, restricted states, deadlocks and timeouts, backup and recovery, depending on how DBA-heavy the role is.
DB2 fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What are the main Db2 platforms? | Landscape | Db2 for z/OS on IBM mainframes and Db2 for Linux, UNIX and Windows. They share SQL and concepts but differ in storage structures, utilities, commands and some SQL features. |
| What is the SQLCA? | Program interface | The SQL communication area, a structure Db2 fills after every statement with SQLCODE, SQLSTATE, warning flags and the number of rows affected (SQLERRD(3)). |
| What do SQLCODE 0, positive and negative values mean? | Error model | Zero is success, positive values are warnings (+100 means no row found or end of cursor), negative values are errors. Programs must test it after every statement. |
| What does -803 mean? | Common codes | An insert or update would create a duplicate value in a unique index or primary key. |
| What does -811 mean? | Common codes | A SELECT INTO or subquery that must return one row returned more than one. Use a cursor, tighten the predicate or decide which row you actually want. |
| What is the difference between -911 and -913? | Locking | Both report a deadlock or timeout. With -911 Db2 has already rolled back the unit of work; with -913 it has not, and the program must decide whether to roll back. |
| What is an indicator variable? | Nulls | A halfword host variable paired with a column. A negative value on fetch means the column was null; setting it to -1 on insert or update stores a null. Fetching a null without one gives -305. |
| What is a table space? | Storage | The storage structure that holds one or more tables' data. Its type and settings decide how data is partitioned, locked and reorganized. |
| What is a clustering index? | Indexes | The index Db2 uses to keep rows physically close in that key order on insert and REORG, which makes range scans on that key cheaper. Only one index can be the clustering one. |
| How do you limit rows returned? | SQL syntax | FETCH FIRST n ROWS ONLY. OPTIMIZE FOR n ROWS is different: it tells the optimizer how many rows you expect to read, which can change the access path. |
Embedded SQL and cursor questions
EXEC SQL
DECLARE C-PAY CURSOR WITH HOLD FOR
SELECT ACCT_ID, AMOUNT, NOTE
FROM PAYMENT
WHERE PAY_DATE = :WS-RUN-DATE
ORDER BY ACCT_ID
END-EXEC
EXEC SQL OPEN C-PAY END-EXEC
PERFORM UNTIL SQLCODE NOT = 0
EXEC SQL
FETCH C-PAY
INTO :WS-ACCT-ID, :WS-AMOUNT, :WS-NOTE :WS-NOTE-IND
END-EXEC
EVALUATE TRUE
WHEN SQLCODE = 0
PERFORM PROCESS-PAYMENT
WHEN SQLCODE = +100
CONTINUE
WHEN OTHER
PERFORM SQL-ERROR-ROUTINE
END-EVALUATE
END-PERFORM
EXEC SQL CLOSE C-PAY END-EXEC- Why WITH HOLD? A normal cursor closes at COMMIT. A batch job that commits every thousand rows needs WITH HOLD to keep reading from where it was, or it must reopen and reposition after each commit.
- How do you update the row a cursor is on? Declare the cursor
FOR UPDATE OFthe columns, thenUPDATE ... WHERE CURRENT OFthe cursor. Db2 takes the right lock when it fetches. - What is multi-row fetch? Fetching a rowset of many rows into host variable arrays in one call, which cuts the number of trips between the program and Db2 for large batch reads.
- What does -305 tell you? A null was fetched into a host variable with no indicator variable. Add an indicator or use COALESCE in the SELECT.
- What are -501 and -502? Fetching from or closing a cursor that is not open, and opening one that is already open. Both are usually flow bugs, often after a commit closed a cursor declared without WITH HOLD.
- How often should a batch program commit? Often enough to release locks and keep restart cheap, not so often that commit overhead dominates. Make the interval a parameter, and save the restart key with each commit.
- What does DCLGEN produce? A copybook with the table's declaration and a matching host variable structure, so the program's fields agree with the column types.
Binding, access paths and tuning
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What happens between writing embedded SQL and running it? | Build process | The precompiler or coprocessor pulls the SQL out into a DBRM and replaces it with calls. The program is compiled and linked; the DBRM is bound into a package, which holds the chosen access paths. A plan lists the packages a program can use. |
| What causes -805? | Bind errors | Db2 cannot find the package for the program in the plan's package list: the package was not bound, was bound into a different collection, or the plan's list does not include that collection. |
| What causes -818? | Consistency token | The load module and the package came from different precompiles, so their consistency tokens do not match. Usually a program was recompiled without a rebind, or the wrong load library is first. |
| Static or dynamic SQL? | SQL types | Static SQL is known at precompile time, bound in advance, with access paths and authorization fixed in the package. Dynamic SQL is prepared at run time, which is flexible but depends on the statement cache and run-time authorization. |
| What is EXPLAIN and what do you look at? | Access paths | It writes the access path into explain tables such as PLAN_TABLE. Look at the access type (index or table space scan), how many index columns match, sort steps, join method and prefetch. |
| Why did a query get slower after a rebind? | Regression | Statistics changed, an index was added or dropped, or the optimizer chose differently. Compare old and new EXPLAIN output, check RUNSTATS timing, and use plan stability features to switch back while you investigate. |
| What does RUNSTATS do? | Statistics | Collects catalog statistics about tables, indexes and column distributions. Without current statistics the optimizer estimates row counts badly and picks poor paths. |
Why does WHERE YEAR(PAY_DATE) = 2026 hurt? | Predicates | Wrapping the column in a function can stop the index on PAY_DATE from being used. A range on the bare column (PAY_DATE BETWEEN ...) lets Db2 match the index. Mainframe interviewers may call this indexable versus non-indexable, or stage 1 versus stage 2. |
SELECT ACCT_ID, PAY_TS, AMOUNT
FROM (
SELECT ACCT_ID, PAY_TS, AMOUNT,
ROW_NUMBER() OVER (PARTITION BY ACCT_ID ORDER BY PAY_TS DESC) AS RN
FROM PAYMENT
) AS T
WHERE RN <= 2
ORDER BY ACCT_ID, PAY_TS DESC
WITH UR;Senior questions: locking, utilities and incidents
- Explain UR, CS, RS and RR. Uncommitted read sees uncommitted changes and takes almost no read locks. Cursor stability, the usual default, locks only the row being read. Read stability keeps locks on rows that qualified. Repeatable read locks everything read so results cannot change. Each step up trades concurrency for consistency.
- When is WITH UR acceptable? For reports where approximate numbers are fine and blocking production is worse. Never for logic that updates based on what it read, because the data may roll back.
- What is lock escalation? When a program holds too many row or page locks, Db2 swaps them for a table or table space lock, which can suddenly block everyone else. Commit more often, check the lock size setting, and look at the access path.
- A batch job and online transactions keep hitting -911 at 9 a.m. What do you do? Find who waits on whom from the diagnostic messages, then fix the cause: batch committing too rarely, both touching rows in opposite order, or a scan locking more than it needs. Moving the batch window is a workaround, not a fix.
- Which utilities do you know and when do they run? LOAD and UNLOAD for bulk data, REORG to restore clustering and reclaim space, RUNSTATS for statistics, COPY for image copies, RECOVER to restore from copies and logs, CHECK DATA for referential integrity after a load.
- What is COPY-pending? A restricted state set, for example, after a LOAD without logging. The object cannot be updated until an image copy is taken, because recovery would otherwise have no starting point.
- How do you design a batch update over fifty million rows? Process in key ranges with commits, keep the restart key in a control table, use multi-row operations, check the access path before running, and agree the window with online users.
- On LUW, what tools do you reach for first?
db2pdand the monitoring table functions for locks and activity,db2lookto extract DDL, and the HADR status when there is a standby. - Clients cannot reach a Db2 LUW server after a weekend reboot. Check that the instance is started and listening on its configured port, then the network side: whether the server's address changed, for example a lease from DHCP on a host that needed a fixed or reserved address, and what the client catalog points to.
Fictional example
- Interviewer
- After last night's release, one batch program fails immediately with SQLCODE -818. Nothing else changed in it. What happened and what do you do?
- Candidate
- -818 means the load module's consistency token does not match the package Db2 found, so the program and its bind came from different precompiles. Something did change: either the program was recompiled during the release and the package was not rebound, or the job is picking up an older load module from a library earlier in the concatenation. I would compare the timestamp in the load module with the package's in the catalog, and check the STEPLIB order. The fix is to bind the package from the matching DBRM, or point the job at the right library. Then I would add a check to the release process that compile and bind always happen together.
How to prepare for a DB2 interview
- Days 1 and 2: learn the SQLCODEs on this page by heart with one cause and one fix each: +100, -305, -501, -502, -803, -805, -811, -818, -911 and -913.
- Day 3: write a cursor program flow on paper with WITH HOLD, commits every N rows and a restart key.
- Day 4: for five queries you know, predict the access path, then explain what would change with a new index or stale statistics.
- Day 5: describe the build chain from source to running program, including where -805 and -818 come from.
- Days 6 and 7: rehearse a locking incident and a performance fix from your own work, and be clear about which platform you used.
Db2 interviews often turn on a single code or a single EXPLAIN row, and a nervous answer can skip the step that proves you know it. Natively, an AI interview assistant for Mac and Windows, transcribes a mock database round on your computer, so you can read back where you named a cause without the evidence. While practicing it can read an EXPLAIN result or an error from a screenshot and suggest what to check, and with Pro or the free trial it works from the résumé and job description you add. Transcripts and notes are stored to review.
Questions people ask
What DB2 questions are asked in interviews?
SQLCODEs such as +100, -803, -811, -805, -818 and -911, cursors with WITH HOLD and FOR UPDATE, indicator variables, precompile and BIND, static versus dynamic SQL, isolation levels, EXPLAIN, RUNSTATS, REORG and locking.
What is the difference between SQLCODE -911 and -913?
Both report a deadlock or timeout. With -911 Db2 has already rolled back the unit of work; with -913 it has not, so the program decides whether to roll back.
What causes SQLCODE -818 in DB2?
The load module and the bound package came from different precompiles, so their consistency tokens do not match. Rebind from the matching DBRM or run the correct load module.
What are the DB2 isolation levels?
Uncommitted read (UR), cursor stability (CS), read stability (RS) and repeatable read (RR), from most concurrency to most consistency.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
