<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="alter-event">
      </a>
      15.1.3 ALTER EVENT Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045189830096">
  </a>
  <a class="indexterm" name="idm46045189828608">
  </a>
  <a class="indexterm" name="idm46045189827120">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa26603456"><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">ALTER</span>
    <span class="token punctuation">[</span><span class="token keyword">DEFINER</span> <span class="token operator">=</span> <span class="token keyword"><em class="replaceable">user</em></span><span class="token punctuation">]</span>
    <span class="token keyword">EVENT</span> <em class="replaceable">event_name</em>
    <span class="token punctuation">[</span><span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span> <span class="token keyword"><em class="replaceable">schedule</em></span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">ON</span> <span class="token keyword">COMPLETION</span> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">PRESERVE</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">RENAME</span> <span class="token keyword">TO</span> <em class="replaceable">new_event_name</em><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">ENABLE</span> <span class="token operator">|</span> <span class="token keyword">DISABLE</span> <span class="token operator">|</span> <span class="token keyword">DISABLE</span> <span class="token keyword">ON</span> {<span class="token keyword">REPLICA</span> <span class="token operator">|</span> <span class="token keyword">SLAVE</span>}<span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">COMMENT</span> <span class="token string">'<em class="replaceable">string</em>'</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">DO</span> <em class="replaceable">event_body</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   The
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   statement changes
      one or more of the characteristics of an existing event without
      the need to drop and recreate it. The syntax for each of the
   <code class="literal">
    DEFINER
   </code>
   ,
   <code class="literal">
    ON SCHEDULE
   </code>
   ,
   <code class="literal">
    ON COMPLETION
   </code>
   ,
   <code class="literal">
    COMMENT
   </code>
   ,
   <code class="literal">
    ENABLE
   </code>
   /
   <code class="literal">
    DISABLE
   </code>
   , and
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   clauses is exactly the same as
      when used with
   <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
    <code class="literal">
     CREATE EVENT
    </code>
   </a>
   . (See
   <a class="xref" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
    Section 15.1.13, “CREATE EVENT Statement”
   </a>
   .)
  </p>
  <p>
   Any user can alter an event defined on a database for which that
      user has the
   <a class="link" href="privileges-provided.html#priv_event">
    <code class="literal">
     EVENT
    </code>
   </a>
   privilege. When
      a user executes a successful
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER
      EVENT
    </code>
   </a>
   statement, that user becomes the definer for the
      affected event.
  </p>
  <p>
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   works only with an
      existing event:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85223607"><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 prompt">mysql&gt;</span> <span class="token keyword">ALTER</span> <span class="token keyword">EVENT</span> no_such_event 
     <span class="token operator">&gt;</span>     <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span> 
     <span class="token operator">&gt;</span>       <span class="token keyword">EVERY</span> <span class="token string">'2:3'</span> <span class="token keyword">DAY_HOUR</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1517 (HY000)<span class="token punctuation">:</span> Unknown event 'no_such_event'</span></code></pre>
  </div>
  <p>
   In each of the following examples, assume that the event named
   <code class="literal">
    myevent
   </code>
   is defined as shown here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35654936"><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">CREATE</span> <span class="token keyword">EVENT</span> myevent
    <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span>
      <span class="token keyword">EVERY</span> <span class="token number">6</span> <span class="token keyword">HOUR</span>
    <span class="token keyword">COMMENT</span> <span class="token string">'A sample comment.'</span>
    <span class="token keyword">DO</span>
      <span class="token keyword">UPDATE</span> myschema<span class="token punctuation">.</span>mytable <span class="token keyword">SET</span> mycol <span class="token operator">=</span> mycol <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The following statement changes the schedule for
   <code class="literal">
    myevent
   </code>
   from once every six hours starting
      immediately to once every twelve hours, starting four hours from
      the time the statement is run:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63867249"><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">ALTER</span> <span class="token keyword">EVENT</span> myevent
    <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span>
      <span class="token keyword">EVERY</span> <span class="token number">12</span> <span class="token keyword">HOUR</span>
    <span class="token keyword">STARTS</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <span class="token number">4</span> <span class="token keyword">HOUR</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   It is possible to change multiple characteristics of an event in a
      single statement. This example changes the SQL statement executed
      by
   <code class="literal">
    myevent
   </code>
   to one that deletes all records from
   <code class="literal">
    mytable
   </code>
   ; it also changes the schedule for the
      event such that it executes once, one day after this
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   statement is run.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45964558"><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">ALTER</span> <span class="token keyword">EVENT</span> myevent
    <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span>
      <span class="token keyword">AT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span>
    <span class="token keyword">DO</span>
      <span class="token keyword">TRUNCATE</span> <span class="token keyword">TABLE</span> myschema<span class="token punctuation">.</span>mytable<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Specify the options in an
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER
      EVENT
    </code>
   </a>
   statement only for those characteristics that you
      want to change; omitted options keep their existing values. This
      includes any default values for
   <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
    <code class="literal">
     CREATE
      EVENT
    </code>
   </a>
   such as
   <code class="literal">
    ENABLE
   </code>
   .
  </p>
  <p>
   To disable
   <code class="literal">
    myevent
   </code>
   , use this
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   statement:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92921487"><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">ALTER</span> <span class="token keyword">EVENT</span> myevent
    <span class="token keyword">DISABLE</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The
   <code class="literal">
    ON SCHEDULE
   </code>
   clause may use expressions
      involving built-in MySQL functions and user variables to obtain
      any of the
   <em class="replaceable">
    <code>
     timestamp
    </code>
   </em>
   or
   <em class="replaceable">
    <code>
     interval
    </code>
   </em>
   values which it contains. You
      cannot use stored routines or loadable functions in such
      expressions, and you cannot use any table references; however, you
      can use
   <code class="literal">
    SELECT FROM DUAL
   </code>
   . This is true for both
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   and
   <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
    <code class="literal">
     CREATE EVENT
    </code>
   </a>
   statements. References
      to stored routines, loadable functions, and tables in such cases
      are specifically not permitted, and fail with an error (see Bug
      #22830).
  </p>
  <p>
   Although an
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   statement
      that contains another
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER EVENT
    </code>
   </a>
   statement in its
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   clause appears
      to succeed, when the server attempts to execute the resulting
      scheduled event, the execution fails with an error.
  </p>
  <p>
   To rename an event, use the
   <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
    <code class="literal">
     ALTER
      EVENT
    </code>
   </a>
   statement's
   <code class="literal">
    RENAME TO
   </code>
   clause.
      This statement renames the event
   <code class="literal">
    myevent
   </code>
   to
   <code class="literal">
    yourevent
   </code>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49505066"><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">ALTER</span> <span class="token keyword">EVENT</span> myevent
    <span class="token keyword">RENAME</span> <span class="token keyword">TO</span> yourevent<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   You can also move an event to a different database using
   <code class="literal">
    ALTER EVENT ... RENAME TO ...
   </code>
   and
   <code class="literal">
    <em class="replaceable">
     <code>
      db_name.event_name
     </code>
    </em>
   </code>
   notation, as shown here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94320040"><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">ALTER</span> <span class="token keyword">EVENT</span> olddb<span class="token punctuation">.</span>myevent
    <span class="token keyword">RENAME</span> <span class="token keyword">TO</span> newdb<span class="token punctuation">.</span>myevent<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   To execute the previous statement, the user executing it must have
      the
   <a class="link" href="privileges-provided.html#priv_event">
    <code class="literal">
     EVENT
    </code>
   </a>
   privilege on both the
   <code class="literal">
    olddb
   </code>
   and
   <code class="literal">
    newdb
   </code>
   databases.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    There is no
    <code class="literal">
     RENAME EVENT
    </code>
    statement.
   </p>
  </div>
  <p>
   The value
   <code class="literal">
    DISABLE ON REPLICA
   </code>
   is used on a
      replica instead of
   <code class="literal">
    ENABLE
   </code>
   or
   <code class="literal">
    DISABLE
   </code>
   to indicate an event that was created
      on the replication source server and replicated to the replica,
      but that is not executed on the replica. Normally,
   <code class="literal">
    DISABLE ON REPLICA
   </code>
   is set automatically as
      required; however, there are some circumstances under which you
      may want or need to change it manually. See
   <a class="xref" href="replication-features-invoked.html" title="19.5.1.16 Replication of Invoked Features">
    Section 19.5.1.16, “Replication of Invoked Features”
   </a>
   , for more
      information.
  </p>
  <p>
   <code class="literal">
    DISABLE ON REPLICA
   </code>
   replaces
   <code class="literal">
    DISABLE ON
      SLAVE
   </code>
   , which is deprecated, and subject to removal in a
      future version of MySQL.
  </p>
 </div>
 <br/>
</div>
