ibm-information-center/dist/eclipse/plugins/i5OS.ic.db2_5.4.0.1/rbafzmstrollbac.htm

218 lines
13 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="dc.language" scheme="rfc1766" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow"/>
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="keywords" content="ROLLBACK statement, ROLLBACK, SQL statements,
unit of work, ending, savepoint, trigger, procedure, WORK clause, HOLD clause" />
<title>ROLLBACK</title>
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
<link rel="stylesheet" type="text/css" href="ic.css" />
</head>
<body>
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
<a name="rollbac"></a>
<h2 id="rollbac"><a href="rbafzmst02.htm#ToC_1254">ROLLBACK</a></h2><a id="idx3087" name="idx3087"></a><a id="idx3088" name="idx3088"></a><a id="idx3089" name="idx3089"></a><a id="idx3090" name="idx3090"></a><a id="idx3091" name="idx3091"></a>
<a name="rolbk"></a>
<p id="rolbk">The ROLLBACK statement can be used to either:</p>
<ul>
<li>End a unit of work and back out all the relational database changes that
were made by that unit of work. If relational databases are the only recoverable
resources used by the application process, ROLLBACK also ends the unit of
work.</li>
<li>Back out only the changes made after a savepoint was set within the unit
of work without ending the unit of work. Rolling back to a savepoint enables
selected changes to be undone.</li></ul>
<a name="wq1711"></a>
<h3 id="wq1711"><a href="rbafzmst02.htm#ToC_1255">Invocation</a></h3>
<p>This statement can be embedded in an application program or issued interactively.
It is an executable statement that can be dynamically prepared.</p><a id="idx3092" name="idx3092"></a><a id="idx3093" name="idx3093"></a>
<p>ROLLBACK is not allowed in a trigger if the trigger program
and the triggering program run under the same commitment definition. ROLLBACK
is not allowed in a procedure if the procedure is called on a connection
to a remote application server or if the procedure is defined as ATOMIC. COMMIT is
not allowed in a function.</p>
<a name="wq1712"></a>
<h3 id="wq1712"><a href="rbafzmst02.htm#ToC_1256">Authorization</a></h3>
<p>None required.</p>
<a name="wq1713"></a>
<h3 id="wq1713"><a href="rbafzmst02.htm#ToC_1257">Syntax</a></h3>
<a href="rbafzmstrollbac.htm#desrolj"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn375.htm"
border="0" /></span><a href="#skipsyn-374"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a> .-WORK-.
>>-ROLLBACK--+------+--+-----------------------------------+--->&lt;
+-HOLD------------------------------+
'-TO--SAVEPOINT--+----------------+-'
'-<span class="italic">savepoint-name</span>-'
</pre>
<a name="skipsyn-374" id="skipsyn-374"></a>
<a name="desrolj"></a>
<h3 id="desrolj"><a href="rbafzmst02.htm#ToC_1258">Description</a></h3>
<p>When ROLLBACK is used without the TO SAVEPOINT clause, the unit
of work in which it is executed is ended. All changes made by SQL schema statements
and SQL data change statements during the unit of work are backed out. For
more information see <a href="rbafzmststates.htm#states">Statements</a>.</p>
<p>The generation of identity values is not under transaction control.
Values generated and consumed by inserting rows into a table that has an identity
column are independent of executing the ROLLBACK statement. Also, executing
the ROLLBACK statement does not affect the IDENTITY_VAL_LOCAL function.</p>
<p>Special registers are not under transaction control. Executing
a ROLLBACK statement does not affect special registers.</p>
<p>Sequences are not under transaction control. Executing a ROLLBACK
statement does not affect the current value generated and consumed by executing
a NEXT VALUE expression.</p>
<p>The impact of ROLLBACK or ROLLBACK TO SAVEPOINT on the contents of a declared
global temporary table is determined by the setting of the ON ROLLBACK clause
of the DECLARE GLOBAL TEMPORARY TABLE statement.</p>
<dl class="parml">
<dt class="bold">WORK </dt><a id="idx3094" name="idx3094"></a>
<dd>ROLLBACK WORK has the same effect as ROLLBACK.
</dd>
<dt class="bold">HOLD </dt><a id="idx3095" name="idx3095"></a>
<dd>Specifies a hold on resources. If specified, currently open
cursors are not closed and all resources acquired during the unit of work,
except locks on the rows of tables, are held. Locks on specific rows implicitly
acquired during the unit of work, however, are released.
<p>At the
end of a ROLLBACK HOLD, the cursor position is the same as it was at the start
of the unit of work, unless</p>
<ul>
<li>ALWBLK(*ALLREAD) was specified when the program or routine that contains
the cursor was created</li>
<li>ALWBLK(*READ) and ALWCPYDTA(*OPTIMIZE) were specified when the program
or routine that contains the cursor was created</li></ul>
</dd>
<dt class="bold">TO SAVEPOINT</dt>
<dd>Specifies that the unit of work is not to be ended and that only a partial
rollback (to a savepoint) is to be performed. If a savepoint name is not specified,
rollback is to the last active savepoint. For example, if in a unit of work,
savepoints A, B, and C are set in that order and then C is released, ROLLBACK
TO SAVEPOINT causes a rollback to savepoint B. <span>If no savepoint is active,
an error is returned.</span>
<dl class="parml">
<dt class="bold"><var class="pv">savepoint-name</var></dt>
<dd>Identifies the savepoint to which to roll back. The name
must identify a savepoint that exists at the current server.
</dd>
</dl>
<p>After a successful ROLLBACK TO SAVEPOINT, the savepoint continues
to exist.</p>
<p>All database changes (including changes made to declared temporary
tables that were declared with the ON ROLLBACK PRESERVE ROWS clause) that
were made after the savepoint was set are backed out. All locks and LOB locators
are retained.</p>
<p>The impact on cursors resulting from a ROLLBACK TO SAVEPOINT
depends on the statements within the savepoint:</p>
<ul>
<li>If the savepoint contains SQL schema statements on which a cursor is dependent,
the cursor is closed. Attempts to use such a cursor after a ROLLBACK TO SAVEPOINT
results in an error.</li>
<li>Otherwise, the cursor is not affected by the ROLLBACK TO SAVEPOINT (it
remains open and positioned).</li></ul>
<p>Any savepoints that are set after the one to which rollback is
performed are released. The savepoint to which rollback is performed is not
released.</p>
</dd>
</dl>
<a name="wq1714"></a>
<h3 id="wq1714"><a href="rbafzmst02.htm#ToC_1259">Notes</a></h3>
<p><span class="bold">Recommended coding practices:</span> Code an explicit COMMIT
or ROLLBACK statement at the end of an application process. Either an implicit
commit or rollback operation will be performed at the end of an application
process depending on the application environment. Thus, a portable application
should explicitly execute a COMMIT or ROLLBACK before execution ends in those
environments where explicit COMMIT or ROLLBACK is permitted.</p>
<p><span class="bold">Other effects of rollback:</span> Rollback without
the TO SAVEPOINT clause and HOLD clause causes the following to occur: </p>
<ul>
<li>All cursors that were opened during the unit of work are closed.</li>
<li>All LOB locators, including those that are held, are freed.</li>
<li>All locks acquired under this unit of work's commitment definition are
released.</li></ul><p class="indatacontent">ROLLBACK has no effect on the state of connections.</p>
<p><span class="bold">Implicit ROLLBACK:</span> The ending of the default activation
group causes an implicit rollback. Thus, an explicit COMMIT or ROLLBACK statement
should be issued before the end of the default activation group.</p>
<p>A ROLLBACK is automatically performed when: </p>
<ol type="1">
<li>The default activation group ends without a final COMMIT being issued.</li>
<li>A failure occurs that prevents the activation group from completing its
work (for example, a power failure).
<p>If the unit of work is in the prepared
state because a COMMIT was in progress when the failure occurred, a rollback
is not performed. Instead, resynchronization of all the connections involved
in the unit of work will occur. For more information, see the <a href="../rzakj/rzakjcommitkickoff.htm">Commitment control</a> topic.</p></li>
<li>A failure occurs that causes a loss of the connection to an application server (for
example, a communications line failure).
<p>If the unit of work is in the
prepared state because a COMMIT was in progress when the failure occurred,
a rollback is not performed. Instead, resynchronization of all the connections
involved in the unit of work will occur. For more information, see the <a href="../rzakj/rzakjcommitkickoff.htm">Commitment control</a> topic.</p></li>
<li>An activation group other than the default activation group ends abnormally.</li></ol>
<p><span class="bold">Row lock limit:</span> A unit of work may include the processing
of up to and including 4 million rows, including rows retrieved during a SELECT
INTO or FETCH statement<sup class="fn"><a href="rbafzmstrollbac.htm#fn36">80</a></sup>, and rows inserted, deleted, or
updated as part of INSERT, DELETE, and UPDATE operations.<sup class="fn"><a id="wq1716" name="wq1716" href="rbafzmstrollbac.htm#wq1717">81</a></sup>
<p><span class="bold">Unaffected statements:</span> The commit and
rollback operations do not affect the DROP SCHEMA statement, and this statement
is not, therefore, allowed if the current isolation level is anything other
than No Commit (NC).</p>
<p><span class="bold">ROLLBACK restrictions:</span> A ROLLBACK statement is not
allowed if commitment control is not active for the activation group. For
information on determining which commitment definition is used, see the <a href="rbafzmstc4comit.htm#cmtdef">commitment definition</a> discussion in the COMMIT statement.</p>
<p>ROLLBACK has no effect on the state of connections.</p>
<p>If, within a unit of work, a CLOSE is followed by a ROLLBACK, all changes
made within the unit of work are backed out. The CLOSE itself is not backed
out and the file is not reopened.</p>
<a name="wq1718"></a>
<h3 id="wq1718"><a href="rbafzmst02.htm#ToC_1260">Examples</a></h3>
<p><span class="italic">Example 1:</span> See the <a href="rbafzmstc4comit.htm#commitexamp">Example</a> under
COMMIT for examples using the ROLLBACK statement.</p>
<p><span class="italic">Example 2:</span> After a unit of recovery started, assume
that three savepoints A, B, and C were set and that C was released:</p>
<pre class="xmp"> <span class="bold">SAVEPOINT</span> A <span class="bold">ON ROLLBACK RETAIN CURSORS</span>;
...
<span class="bold">SAVEPOINT</span> B <span class="bold">ON ROLLBACK RETAIN CURSORS</span>;
....
<span class="bold">SAVEPOINT</span> C <span class="bold">ON ROLLBACK RETAIN CURSORS</span>;
...
<span class="bold">RELEASE SAVEPOINT</span> C</pre>
<p>Roll back all database changes only to savepoint A:</p>
<pre class="xmp"> <span class="bold">ROLLBACK WORK TO SAVEPOINT</span> A</pre>
<p>If a savepoint name was not specified (that is, ROLLBACK WORK
TO SAVEPOINT), the rollback would be to the last active savepoint that was
set, which is B.</p><a id="idx3096" name="idx3096"></a><a id="idx3097" name="idx3097"></a>
<hr /><div class="fnnum"><a id="fn36" name="fn36">80</a>.</div>
<div class="fntext">Unless you specified COMMIT(*CHG) or COMMIT(*CS), in which case
these rows are not included in this total.</div><div class="fnnum"><a id="wq1717" name="wq1717" href="rbafzmstrollbac.htm#wq1716">81</a>.</div>
<div class="fntext">This limit also
includes: </p>
<ul>
<li>Any rows accessed or changed through files opened under commitment control
through high-level language file processing</li>
<li>Any rows deleted, updated, or inserted as a result of a trigger or CASCADE,
SET NULL, or SET DEFAULT referential integrity delete rule.</li></ul></div>
<br />
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstrevoket.htm">Previous Page</a> | <a href="rbafzmstsvpt.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
<a href="rbafzmstindex.htm#index">Index</a> ]
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
</body>
</html>