I am a bit confused with the SET INTEGRITY concept in DB2, why we can OFF the set integrity check to put the table in PENDING state ? does that mean that we can neglect the constraint definitions on the table and insert invalid rows into table arbitrarily ? if that is the case why we create the constraint at the first place ?

further more, there is options to turn on and off access. I am further confused, does that mean even before the integrity of table data being checked, we can allow the data to be read accessed ? is that same as saying we allow dirty read here?

+another question is, if that integrity check is put off, how to bring the table out of pending state ? does this always requires manual intervention?

  • Is it possible to execute the set integrity query from db2 comman editor? – user15556 Nov 22 '12 at 15:46
  • @Anandan you should post this as a new question, not as a comment – ypercubeᵀᴹ Nov 22 '12 at 16:00

Simple answer do not mix with your other assumption. I hope you know primary key and foreign key relation for eg:

  • Primary key in a table is nothing but a column that is unique + not null where as foreign key is referring to that primary key table column.

  • If data inserting into foreign key table column that not matches to primary key it is nothing but duplicate record and it'll not insert with error throw.

  • In DB2 Load it'll not check duplicate/dependencies between two tables (primary key and foreign key table) bypass records and load data.

DB2 recommends checking dependency/duplicate record in terms of set integrity check after Load, if no duplicate/dependency found it'll take out your table from check integrity and if found you can create another table to put duplicate records into that and bring out from check integrity.

Query to check tables in check integrity after Load:

db2 "select 'set integrity for '||tabschema||'.'||tabname||' immediate checked ;' 
from syscat.tables where tabschema='<schemaname for eg:HEDW' and not (status='N'
and access_mode='F')"

Command to bring out from check integrity:

db2 set integrity for HEDW    .EMPLY_BON_TIME immediate checked
DB20000I  The SQL command completed successfully.
| improve this answer | |

According to IBM's documentation: "Typically, you need to manually perform integrity processing for a table in three situations: After loading data into a table; when altering a table by adding constraints on the table; and when altering a table to add a generated column."

That would be the why you need to do it. We use it right after we use the LOAD command as this bypasses referential integrity to load (for lack of a better word) a ton of records into tables. We end up needing to use SET INTEGRITY when we are done to have it check the integrity and verify our tables can be used.

In our case we use:


And yes, you do have to run the SET INTEGRITY command for each table that is in a pending state. (We use scripts to do it in our case to simplify things.)

For more information about the command see SET INTEGRITY for all available options.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.