12.07.2015 Views

DB2 data manipulation

DB2 data manipulation

DB2 data manipulation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

developerWorks®ibm.com/developerWorksangry customer who never received his or her purchase, but you would introduce aninaccuracy into the inventory. Thus, all SQL queries for the purchase must bedefined as a single atomic operation.Steps in a transactionNow see what steps need to go into a <strong>DB2</strong> transaction. Before you start, aconnection must be established with the <strong>data</strong>base against which the transactionexecutes.Start the transaction with an executable statement. An executable statement alwaysoccurs within a transaction. If a program contains an executable statement after atransaction ends, it starts a new transaction. The following are not executablestatements:BEGIN DECLARE SECTIONEND DECLARE SECTIONINCLUDE SQLCAINCLUDE SQLDADECLARE CURSORWHENEVEREnd the transaction in the following way:COMMITROLLBACKThe COMMIT statement ends the transaction and makes the changes visible to otherprocesses. Remember, you should commit regularly and do so exclusively beforeprogram termination. <strong>DB2</strong> automatically rolls back transactions if you do notexplicitly commit them on Windows operating systems. On other operating systems,<strong>DB2</strong> commits all pending transactions during program termination automatically .The ROLLBACK statement returns the <strong>data</strong>base to the state it was in before thetransaction ran. The rollback prevents the changes being applied to the <strong>data</strong>baseafter the last transaction commits. This ensures that either all operations in thetransaction are committed, or none are. <strong>DB2</strong> rolls back changes under the followingconditions:• A log full condition• A system condition that causes the system process to endTo avoid loop failure, use WHENEVER SQLWARNING CONTINUE or WHENEVERSQLERROR CONTINUE before a ROLLBACK statement. A ROLLBACK statement hasno effect on the contents of host variables.You should terminate your application by taking the following steps:<strong>DB2</strong> <strong>data</strong> <strong>manipulation</strong>Page 18 of 25© Copyright IBM Corporation 1994, 2007. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!