Exception tables are user-created tables that mimic the definition of the tables that are specified to be checked using the SET INTEGRITY statement with the IMMEDIATE CHECKED option. They are used to store copies of the rows that violate constraints in the tables being checked.
The exception tables that are used by the load utility are identical to the ones described here, and can therefore be reused during checking with the SET INTEGRITY statement.
The rules for creating an exception table are as follows:
The information in the "message" column has the following structure:
| Field number | Contents | Size | Comments |
|---|---|---|---|
| 1 | Number of constraint violations | 5 bytes | Right justified padded with '0' |
| 2 | Type of first constraint violation | 1 byte | 'K' - Check Constraint violation 'F' - Foreign Key violation 'G' - Generated Column violation 'I' - Unique Index violationa 'D' - Delete Cascade violation 'P' - Data Partitioning violation 'S' - Invalid Row Security Label 'L' - DB2® LBAC Write rules violation 'X' - XML values index violationd |
| 3 | Length of constraint/columnb /index IDc | 5 bytes | Right justified padded with '0' |
| 4 | Constraint name/Column nameb/index IDc | length from the previous field | |
| 5 | Separator | 3 bytes | <space><colon><space> |
| 6 | Type of next constraint violation | 1 byte | 'K' - Check Constraint violation 'F' - Foreign Key violation 'G' - Generated Column violation 'I' - Unique Index violation 'D' - Delete Cascade violation 'P' - Data Partitioning violation 'S' - Invalid Row Security Label 'L' - DB2 LBAC Write rules violation 'X' - XML values index violationd |
| 7 | Length of constraint/column/index ID | 5 bytes | Right justified padded with '0' |
| 8 | Constraint name/Column name/Index ID | length from the previous field | |
| ..... | ..... | ..... | Repeat Field 5 through 8 for each violation |
|
|||
The information in exception tables can be processed in various ways. Data can be corrected and rows re-inserted into the original tables.
If there are no INSERT triggers on the original table, transfer the corrected rows by issuing an INSERT statement with a subquery on the exception table.
No explicit provision is made to prevent the firing of triggers when inserting rows from exception tables.
Only one violation per row is reported for unique index violations.
If values with LONG VARCHAR, LONG VARGRAPHIC, or LOB data types are in the table, the values are not inserted into the exception table in the case of unique index violations.
The message column structure in an exception table is a concatenated list of constraint names, lengths, and delimiters, as described earlier. This information can be queried.
WITH IV (C1, C2, MSGCOL, CONSTNAME, I, J) AS
(SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, 12,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0)))),
1,
15+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0))
FROM E1
UNION ALL
SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, J+6,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0)))),
I+1,
J+9+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0))
FROM IV
WHERE I < INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,1,5)),5,0))
) SELECT C1, C2, CONSTNAME FROM IV;
WITH IV (C1, C2, MSGCOL, CONSTNAME, I, J) AS
(SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, 12,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0)))),
1,
15+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0))
FROM E1
UNION ALL
SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, J+6,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0)))),
I+1,
J+9+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0))
FROM IV
WHERE I < INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,1,5)),5,0))
) SELECT C1, C2, CONSTNAME FROM IV WHERE CONSTNAME = 'constraintname';
WITH IV (C1, C2, MSGCOL, CONSTNAME, CONSTTYPE, I, J) AS
(SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, 12,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0)))),
CHAR(SUBSTR(MSGCOL, 6, 1)),
1,
15+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,7,5)),5,0))
FROM E1
UNION ALL
SELECT C1, C2, MSGCOL,
CHAR(SUBSTR(MSGCOL, J+6,
INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0)))),
CHAR(SUBSTR(MSGCOL, J, 1)),
I+1,
J+9+INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,J+1,5)),5,0))
FROM IV
WHERE I < INTEGER(DECIMAL(VARCHAR(SUBSTR(MSGCOL,1,5)),5,0))
) SELECT C1, C2, CONSTNAME FROM IV WHERE CONSTTYPE = 'K';