gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

71 lines
7.1KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>BEGIN</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="sql-analyze.html" title="ANALYZE" /><link rel="next" href="sql-call.html" title="CALL" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">BEGIN</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-analyze.html" title="ANALYZE">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-call.html" title="CALL">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-BEGIN"><div class="titlepage"></div><a id="id-1.9.3.47.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">BEGIN</span></h2><p>BEGIN — start a transaction block</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. BEGIN [ WORK | TRANSACTION ] [ <em class="replaceable"><code>transaction_mode</code></em> [, ...] ]
  4. <span class="phrase">where <em class="replaceable"><code>transaction_mode</code></em> is one of:</span>
  5. ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
  6. READ WRITE | READ ONLY
  7. [ NOT ] DEFERRABLE
  8. </pre></div><div class="refsect1" id="id-1.9.3.47.5"><h2>Description</h2><p>
  9. <code class="command">BEGIN</code> initiates a transaction block, that is,
  10. all statements after a <code class="command">BEGIN</code> command will be
  11. executed in a single transaction until an explicit <a class="xref" href="sql-commit.html" title="COMMIT"><span class="refentrytitle">COMMIT</span></a> or <a class="xref" href="sql-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a> is given.
  12. By default (without <code class="command">BEGIN</code>),
  13. <span class="productname">PostgreSQL</span> executes
  14. transactions in <span class="quote">“<span class="quote">autocommit</span>”</span> mode, that is, each
  15. statement is executed in its own transaction and a commit is
  16. implicitly performed at the end of the statement (if execution was
  17. successful, otherwise a rollback is done).
  18. </p><p>
  19. Statements are executed more quickly in a transaction block, because
  20. transaction start/commit requires significant CPU and disk
  21. activity. Execution of multiple statements inside a transaction is
  22. also useful to ensure consistency when making several related changes:
  23. other sessions will be unable to see the intermediate states
  24. wherein not all the related updates have been done.
  25. </p><p>
  26. If the isolation level, read/write mode, or deferrable mode is specified, the new
  27. transaction has those characteristics, as if
  28. <a class="xref" href="sql-set-transaction.html" title="SET TRANSACTION"><span class="refentrytitle">SET TRANSACTION</span></a>
  29. was executed.
  30. </p></div><div class="refsect1" id="id-1.9.3.47.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">WORK</code><br /></span><span class="term"><code class="literal">TRANSACTION</code></span></dt><dd><p>
  31. Optional key words. They have no effect.
  32. </p></dd></dl></div><p>
  33. Refer to <a class="xref" href="sql-set-transaction.html" title="SET TRANSACTION"><span class="refentrytitle">SET TRANSACTION</span></a> for information on the meaning
  34. of the other parameters to this statement.
  35. </p></div><div class="refsect1" id="id-1.9.3.47.7"><h2>Notes</h2><p>
  36. <a class="xref" href="sql-start-transaction.html" title="START TRANSACTION"><span class="refentrytitle">START TRANSACTION</span></a> has the same functionality
  37. as <code class="command">BEGIN</code>.
  38. </p><p>
  39. Use <a class="xref" href="sql-commit.html" title="COMMIT"><span class="refentrytitle">COMMIT</span></a> or
  40. <a class="xref" href="sql-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a>
  41. to terminate a transaction block.
  42. </p><p>
  43. Issuing <code class="command">BEGIN</code> when already inside a transaction block will
  44. provoke a warning message. The state of the transaction is not affected.
  45. To nest transactions within a transaction block, use savepoints
  46. (see <a class="xref" href="sql-savepoint.html" title="SAVEPOINT"><span class="refentrytitle">SAVEPOINT</span></a>).
  47. </p><p>
  48. For reasons of backwards compatibility, the commas between successive
  49. <em class="replaceable"><code>transaction_modes</code></em> can be
  50. omitted.
  51. </p></div><div class="refsect1" id="id-1.9.3.47.8"><h2>Examples</h2><p>
  52. To begin a transaction block:
  53. </p><pre class="programlisting">
  54. BEGIN;
  55. </pre></div><div class="refsect1" id="id-1.9.3.47.9"><h2>Compatibility</h2><p>
  56. <code class="command">BEGIN</code> is a <span class="productname">PostgreSQL</span>
  57. language extension. It is equivalent to the SQL-standard command
  58. <a class="xref" href="sql-start-transaction.html" title="START TRANSACTION"><span class="refentrytitle">START TRANSACTION</span></a>, whose reference page
  59. contains additional compatibility information.
  60. </p><p>
  61. The <code class="literal">DEFERRABLE</code>
  62. <em class="replaceable"><code>transaction_mode</code></em>
  63. is a <span class="productname">PostgreSQL</span> language extension.
  64. </p><p>
  65. Incidentally, the <code class="literal">BEGIN</code> key word is used for a
  66. different purpose in embedded SQL. You are advised to be careful
  67. about the transaction semantics when porting database applications.
  68. </p></div><div class="refsect1" id="id-1.9.3.47.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-commit.html" title="COMMIT"><span class="refentrytitle">COMMIT</span></a>, <a class="xref" href="sql-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a>, <a class="xref" href="sql-start-transaction.html" title="START TRANSACTION"><span class="refentrytitle">START TRANSACTION</span></a>, <a class="xref" href="sql-savepoint.html" title="SAVEPOINT"><span class="refentrytitle">SAVEPOINT</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-analyze.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-call.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ANALYZE </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> CALL</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1