Home > Ask the Data management / BI Experts > Questions & Answers > Rollback changes coming undone
Ask The Data Management Expert: Questions & Answers
EMAIL THIS

Rollback changes coming undone

Craig Mullins, Years 2005-2006 EXPERT RESPONSE FROM: Craig Mullins, Years 2005-2006

Pose a Question
Other Data Management Categories
Meet all Data Management Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 19 December 2003
I have a cursor that selects "n" rows from a table based on certain conditions. For each of the rows selected, certain functions have to be performed that updates a few tables. If there is any error while processing, the updates to the table are rolled back and continue processing with the next fetched row. But, rollback is forcing the cursor to close, which gives a -501 error. How do I handle this? Is there any way to avoid the cursor from closing, even as a rollback is issued? Please advise.

>
Your solution will be to use an application SAVEPOINT. This feature was added to DB2 for OS/390 under Version 7. You can think of a SAVEPOINT as a sub-UOW (unit of work) "stability" point. You can code application logic to undo any data modifications and database schema changes that were made since the application set the SAVEPOINT. Application development should be more efficient using SAVEPOINTs because you will not need to include contingency and what-if logic in your application code.

Issuing a SAVEPOINT does not COMMIT work to DB2. It is simply a mechanism for registering milestones within a transaction or program. Let's learn by example. Consider the following pseudo-code:

SAVEPOINT POINTX ON ROLLBACK RETAIN CURSORS;

...Subsequent processing...

ROLLBACK TO SAVEPOINT POINTX;

The ROLLBACK will cause any data or schema changes made in the "subsequent processing" to be undone. It is permissible to code multiple SAVEPOINTs within a UOW and you can ROLLBACK to any SAVEPOINT (as long as you do not reuse the SAVEPOINT name). The UNIQUE key word can be specified to ensure that the SAVEPOINT name is not reused within the unit of recovery.

There are two clauses that can be specified to further define the nature of the SAVEPOINT when a ROLLBACK is issued:

RETAIN CURSORS -- specifies that any cursors that are opened after the SAVEPOINT is set are not tracked, and will not be closed when rolling back to that SAVEPOINT. You will want to use this.

RETAIN LOCKS -- specifies that any locks that are acquired after the SAVEPOINT is set are not tracked, and will not be released when rolling back to the SAVEPOINT.

Keep in mind though, that even if RETAIN CURSORS is specified some of the cursors may not be usable. For example, if the ROLLBACK removes a row (that is, rolls back an INSERT) on which the cursor was positioned, an error will arise.

Editor's note: Do you agree with this expert's response? If you have more to share, post it in one of our discussion forums.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
IBM DB2 management
How to select an MPP database: DB2 vs. Teradata
What are the top database management systems (DBMS)?
Are there benefits to using both Teradata and a DB2 database?
Tips for evaluating top database management systems and choosing a small DBMS
Exec explains IBM's Information On Demand (IOD) initiative
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 7
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 6
IBM DB2 9 Fundamentals certification (Exam 730): Sample questions about tables, Part 5
DB2 basics
IBM DB2 basics

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts