<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="ansi-diff-comments">
      </a>
      1.7.2.4 '--' as the Start of a Comment
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045333175952">
  </a>
  <a class="indexterm" name="idm46045333174496">
  </a>
  <p>
   Standard SQL uses the C syntax
   <code class="literal">
    /* this is a comment
          */
   </code>
   for comments, and MySQL Server supports this
          syntax as well. MySQL also support extensions to this syntax
          that enable MySQL-specific SQL to be embedded in the comment;
          see
   <a class="xref" href="comments.html" title="11.7 Comments">
    Section 11.7, “Comments”
   </a>
   .
  </p>
  <p>
   MySQL Server also uses
   <code class="literal">
    #
   </code>
   as the start
          comment character. This is nonstandard.
  </p>
  <p>
   Standard SQL also uses
   <span class="quote">
    “
    <span class="quote">
     <code class="option">
      --
     </code>
    </span>
    ”
   </span>
   as a
          start-comment sequence. MySQL Server supports a variant of the
   <code class="literal">
    --
   </code>
   comment style; the
   <code class="literal">
    --
   </code>
   start-comment sequence is accepted as such, but must be
          followed by a whitespace character such as a space or newline.
          The space is intended to prevent problems with generated SQL
          queries that use constructs such as the following, which
          updates the balance to reflect a charge:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6123982"><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">UPDATE</span> <span class="token keyword">account</span> <span class="token keyword">SET</span> balance<span class="token operator">=</span>balance<span class="token operator">-</span>charge
<span class="token keyword">WHERE</span> account_id<span class="token operator">=</span>user_id</code></pre>
  </div>
  <p>
   Consider what happens when
   <code class="literal">
    charge
   </code>
   has a
          negative value such as
   <code class="literal">
    -1
   </code>
   , which might be
          the case when an amount is credited to the account. In this
          case, the generated statement looks like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41148760"><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">UPDATE</span> <span class="token keyword">account</span> <span class="token keyword">SET</span> balance<span class="token operator">=</span>balance<span class="token comment" spellcheck="true">--1</span>
<span class="token keyword">WHERE</span> account_id<span class="token operator">=</span><span class="token number">5752</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   <code class="literal">
    balance--1
   </code>
   is valid standard SQL, but
   <code class="literal">
    --
   </code>
   is interpreted as the start of a
          comment, and part of the expression is discarded. The result
          is a statement that has a completely different meaning than
          intended:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa26420572"><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">UPDATE</span> <span class="token keyword">account</span> <span class="token keyword">SET</span> balance<span class="token operator">=</span>balance
<span class="token keyword">WHERE</span> account_id<span class="token operator">=</span><span class="token number">5752</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   This statement produces no change in value at all. To keep
          this from happening, MySQL requires a whitespace character
          following the
   <code class="literal">
    --
   </code>
   for it to be recognized as
          a start-comment sequence in MySQL Server, so that an
          expression such as
   <code class="literal">
    balance--1
   </code>
   is always
          safe to use.
  </p>
 </div>
 <br/>
</div>
