I want to enable commitment control
with DB2 tables
to use COMMIT
on success and ROLLBACK
on failure to perform operations with tables.
I want to ensure that nothing goes wrong with the database and that the integrity must be maintained. What are the prerequisites to use commitment control
with DB2 SQL
and how can I implement it?
Commitment control
is by default enabled inIBM DB2
since the following statement cannot update a fileupdate libname/filename set fld1 = 'test' where id = 1;
.You need to add
with NC
to the end of the above statement todisable the commitment control
andcommit
the update operation on the table immediately.update libname/filename set fld1 = 'test' where id = 1 with NC;
For using
commitment control
you need to enablejournalling
on the files first. You can follow the below steps to enable thejournalling
of files.journal reciever
namedjrnrcv0001
using this command.CRTJRNRCV JRNRCV(libname/JRNRCV0001)
journal
namedJRN0000001
and attach the journal receiverJRNRCV0001
using this command.CRTJRN JRN(libname/JRN0000001) JRNRCV(libname/JRNRCV0001)
journalling
of files using a journalJRN0000001
.STRJRNPF FILE(libname/filename) JRN(JRN0000001) IMAGES(*AFTER)
Once the journalling is started on files and then if you perform any update to this file through your program, you must either commit or roll back the update before your program ends. If you do not do this then the lock on the file will remain present after the program ends. You can use
COMMIT
command to commit the changes andROLLBACK
command to roll back the last commit or simply rollback call for the operation done so far that were not yet committed.