Mainframe Path Start learning free
CoreError and abend codes-530

SQLCODE -530 — foreign key violation

An INSERT or UPDATE set a foreign key to a value with no matching parent row. Usually a load-order or missing-reference-data problem.

What happened

An insert or update of child rows fails, often for a batch of records that share one parent key.

Program output via DSNTIAR (illustrative)
DSNT408I SQLCODE = -530, ERROR:  THE INSERT OR UPDATE VALUE OF
         FOREIGN KEY FKORDCUS IS INVALID
DSNT418I SQLSTATE   = 23503 SQLSTATE RETURN CODE

What it means

A referential constraint says every non-null foreign key value in the child table must exist as a key in the parent table. Your statement would break that rule, so Db2 rejected it. The SQLSTATE is 23503.

The SQLERRMC token gives the constraint name. Look it up in SYSIBM.SYSRELS (RELNAME, with TBNAME as the child and REFTBNAME as the parent) and SYSIBM.SYSFOREIGNKEYS for the columns.

Typical causes

Symptoms

Fails for specific key values. Often many records fail with the same missing parent. Different from -803 (duplicate in a unique index) and from -532, which is about deleting a parent that still has children.

Where to look

How to diagnose

  1. Record the constraint name and the failing key.
  2. Find the parent table and columns from the catalog.
  3. Query the parent for the key. Check for trailing spaces or case differences.
  4. Check whether the parent load or update job ran, and in the right order.
  5. Count how many input records reference missing parents.

How to fix

Load or correct the parent data first, then rerun or restart the child step. If parents are genuinely missing, the data owner decides whether to add them or reject the children. To turn the raw SQLCA into readable text, call DSNTIAR (DSNTIAC in CICS) with the SQLCA and a message buffer, or use GET DIAGNOSTICS to fetch MESSAGE_TEXT, RETURNED_SQLSTATE and DB2_RETURNED_SQLCODE. Either way, write the full message to the job log before the program ends.

How to prevent

Production considerations

Interview question

A child-table load fails with SQLCODE -530. How do you investigate?

Stuck on something else?
Ask the community or search the full course.

Ask a question