<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="savepoint">
      </a>
      15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045178627760">
  </a>
  <a class="indexterm" name="idm46045178626720">
  </a>
  <a class="indexterm" name="idm46045178625648">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66696333"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SAVEPOINT</span> <em class="replaceable">identifier</em>
<span class="token keyword">ROLLBACK</span> <span class="token punctuation">[</span><span class="token keyword">WORK</span><span class="token punctuation">]</span> <span class="token keyword">TO</span> <span class="token punctuation">[</span><span class="token keyword">SAVEPOINT</span><span class="token punctuation">]</span> <em class="replaceable">identifier</em>
<span class="token keyword">RELEASE</span> <span class="token keyword">SAVEPOINT</span> <em class="replaceable">identifier</em></code></pre>
  </div>
  <p>
   <code class="literal">
    InnoDB
   </code>
   supports the SQL statements
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     SAVEPOINT
    </code>
   </a>
   ,
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     ROLLBACK TO
      SAVEPOINT
    </code>
   </a>
   ,
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     RELEASE
      SAVEPOINT
    </code>
   </a>
   and the optional
   <code class="literal">
    WORK
   </code>
   keyword for
   <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
    <code class="literal">
     ROLLBACK
    </code>
   </a>
   .
  </p>
  <p>
   The
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     SAVEPOINT
    </code>
   </a>
   statement sets a
      named transaction savepoint with a name of
   <em class="replaceable">
    <code>
     identifier
    </code>
   </em>
   . If the current transaction
      has a savepoint with the same name, the old savepoint is deleted
      and a new one is set.
  </p>
  <p>
   The
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     ROLLBACK TO
      SAVEPOINT
    </code>
   </a>
   statement rolls back a transaction to the
      named savepoint without terminating the transaction. Modifications
      that the current transaction made to rows after the savepoint was
      set are undone in the rollback, but
   <code class="literal">
    InnoDB
   </code>
   does
   <span class="emphasis">
    <em>
     not
    </em>
   </span>
   release the row locks that were stored in
      memory after the savepoint. (For a new inserted row, the lock
      information is carried by the transaction ID stored in the row;
      the lock is not separately stored in memory. In this case, the row
      lock is released in the undo.) Savepoints that were set at a later
      time than the named savepoint are deleted.
  </p>
  <p>
   If the
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     ROLLBACK TO
      SAVEPOINT
    </code>
   </a>
   statement returns the following error, it
      means that no savepoint with the specified name exists:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa17695036"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-none">ERROR 1305 (42000): SAVEPOINT <em class="replaceable">identifier</em> does not exist</code></pre>
  </div>
  <p>
   The
   <a class="link" href="savepoint.html" title="15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements">
    <code class="literal">
     RELEASE
      SAVEPOINT
    </code>
   </a>
   statement removes the named savepoint from the
      set of savepoints of the current transaction. No commit or
      rollback occurs. It is an error if the savepoint does not exist.
  </p>
  <p>
   All savepoints of the current transaction are deleted if you
      execute a
   <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
    <code class="literal">
     COMMIT
    </code>
   </a>
   , or a
   <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
    <code class="literal">
     ROLLBACK
    </code>
   </a>
   that
      does not name a savepoint.
  </p>
  <p>
   A new savepoint level is created when a stored function is invoked
      or a trigger is activated. The savepoints on previous levels
      become unavailable and thus do not conflict with savepoints on the
      new level. When the function or trigger terminates, any savepoints
      it created are released and the previous savepoint level is
      restored.
  </p>
 </div>
 <br/>
</div>
