title: Ambiguous error in creating BEFORE INSERT trigger
body: <p>I have a <code>Reservation</code> table and am creating a BEFORE INSERT trigger that checks whether a user's reservation is already in the database, i.e. prevent him from making duplicate reservations. This is done to signal the front-end that the user is unable to make a duplicate reservation.</p>
  
  <p>However, mySQL raises this error: <code>ERROR 1064 (42000) at line 3: 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 '' at line 5</code>. For some reason when the body between <code>BEGIN</code> and <code>END</code> is empty, it doesn't raise an error. </p>
  
  <pre><code>CREATE TABLE reservation (
      customer_user_id integer,
      date integer,
      time integer,
      name varchar(100)
  );
  
  CREATE TRIGGER trigger_name
  BEFORE INSERT -- error raised in this line
  ON reservation FOR EACH ROW
  BEGIN
      DECLARE sum INT;
  
      SELECT COUNT(*) 
      INTO sum 
      FROM reservation r
      WHERE (r.customer_user_id = new.customer_user_id)
      AND (r.date = new.date)
      AND (r.time = new.time);
  
      IF sum = 0 THEN
          INSERT INTO reservation values (new.customer_user_id, new.date, new.time, new.name);
      ELSE 
          RAISE NOTICE 'duplicate'
      END IF;
  END; 
  </code></pre>
  
  <p>Additionally, could this trigger be a constraint on the table <code>Reservation</code>? E.g. <code>(customer_user_id, date, time) UNIQUE</code> of sorts, which would prevent adding of duplicates, but I am clueless on how to "signal" the front-end which in turn prompts the user that they cannot add a duplicate reservation. 
  Sorry if some parts of the code might be weird, I'm new to SQL and was taught pSQL. </p>
  
  <p>Thanks in advance!</p>