title: Make a query in mysql without invoking a trigger (How to disable a trigger)
body: <p>I have 2 tables: <code>comments</code> and <code>comments_likes</code>.</p>
  
  <hr>
  
  <p><strong>comments</strong></p>
  
  <pre><code>id     
  message
  likes  
  </code></pre>
  
  <p><strong>triggers</strong>:</p>
  
  <p><em>AFTER DELETE</em></p>
  
  <pre><code>DELETE FROM comments_likes WHERE comment_id = OLD.id;
  </code></pre>
  
  <hr>
  
  <p><strong>comments_likes</strong></p>
  
  <pre><code>id        
  comment_id
  </code></pre>
  
  <p><strong>triggers</strong>:</p>
  
  <p><em>AFTER INSERT</em></p>
  
  <pre><code>UPDATE comments SET likes = likes + 1 WHERE comments.id = NEW.comment_id;
  </code></pre>
  
  <p><em>AFTER DELETE</em></p>
  
  <pre><code>UPDATE comments SET likes = likes - 1 WHERE comments.id = OLD.comment_id;
  </code></pre>
  
  <p><em>AFTER UPDATE</em></p>
  
  <pre><code>**omited code, updates comments**
  </code></pre>
  
  <hr>
  
  <p>So the question is, <strong>can I disable the triggers when activating them from another trigger</strong>?</p>
  
  <p>What I want is do something likes this:</p>
  
  <p><em>AFTER DELETE</em></p>
  
  <pre><code>IF NOT called_from_another_trigger() THEN
      UPDATE comments SET likes = likes - 1 WHERE comments.id = OLD.comment_id;
  END IF;
  </code></pre>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>A non optimized solution would be (very slow query... makes a query for each LIKE register):</p>
  
  <pre><code>BEGIN
      IF (SELECT id FROM comments WHERE comments.id = OLD.comment_id) THEN
          UPDATE comments SET comments.cache_likes = comments.cache_likes - 1 WHERE comments.id = OLD.comment_id;
      END IF;
  END
  </code></pre>
  
  <p>UPDATE <code>LOW PRIORITY</code> and <code>IGNORE</code> don't works.</p>
  
  <p><strong>[EDIT 2]</strong></p>
  
  <p>I have another idea, is possible to set a global variable in the first trigger and read it from the other trigger?</p>
  
  <p>Ex:</p>
  
  <p>first trigger:</p>
  
  <pre><code>@disable_triggers = true;
  // do the stuff that calls another triggers
  @disable_triggers = false;
  </code></pre>
  
  <p>other trigger:</p>
  
  <pre><code>if @disable_triggers = false then
      // do the stuff
  end if;
  </code></pre>