title: When are MYSQL delimiters useful?
body: <p>I am writing SQL to create a trigger for a table in my database. This code should be in a script we can run whenever we spawn a new database.</p>
  
  <p>I have been reading the SQL doc to understand how to do this and eventually came up with a query of this type:</p>
  
  <pre><code>DELIMITER $$
  CREATE TRIGGER calendar_event_after_insert AFTER INSERT 
  ON calendar_event
  FOR EACH ROW
  BEGIN
    IF @log_calendar_event_id = 'YES'
    THEN
      ...
    END IF;
    IF @log_calendar_event_name = 'YES'
    THEN
      ...
    END IF;
    ...
  END
  $$
  DELIMITER ;
  </code></pre>
  
  <p>Now I am getting an error on my use of DELIMITER, and I admit I don't understand much of how that works. My basic understanding is that since there are multiple queries inside this big one that all end with a <code>;</code> I need to tell sql when this query ends using another delimiter.</p>
  
  <p>After reading a bit about delimiters this seems like the right syntax to me, and on top of that i have been running this query in sequel pro and it works at times and at times it does not (weird, I know).</p>
  
  <p>So eventually I decided to remove the delimiters part and everything works smoothly. I am a bit worried this will have side effects tho.</p>
  
  <p>So my question is: when are delimiters used? are they useful in my case? if so, what am I doing wrong here?</p>
  
  <hr>
  
  <p><strong>EDIT as requested in comments</strong></p>
  
  <p>This is the error I get when running the query: </p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 'DELIMITER $$ CREATE TRIGGER calendar_event_after_insert AFTER
    INSERT ON calenda' at line 1</p>
  </blockquote>
  
  <p>FYI we have an old version of MYSQL installed on our dev machines -- MYSQL 5.1.73</p>