title: MySQL Trigger: Prevent Insert by IF statement
body: <p>I try to write my first trigger for a MySQL Database. It should <strong>prevent an insert</strong> (and later also updates) on "<strong>course_student</strong>" in context of the current time and the given timestamps in "<strong>capacity</strong>", but i'm still getting a syntax error.</p>
  
  <pre><code>DELIMITER $$
  
  CREATE TRIGGER checkSubscribeTimeCourse 
  BEFORE INSERT ON course_student
  REFERENCING NEW AS new
  FOR EACH ROW 
  
  BEGIN
  
      IF (SELECT COUNT(*) FROM capacity c, course_capacity cc 
          WHERE c.cid = cc.cid 
          AND cc.cid = new.cid
          AND (c.end &gt;= CURRENT_TIMESTAMP OR c.end IS NULL)
          AND (c.start &lt;= CURRENT_TIMESTAMP OR c.start IS NULL)&lt;1)
      THEN
          SIGNAL SQLSTATE '45000'
          SET MESSAGE_TEXT = 'Error'
      END IF
  
  END
  
  DELIMITER ;
  </code></pre>
  
  <p><em>I translated all names; so maybe there are typing errors.</em></p>