title: Create trigger in MySQL to log changes in database
body: <p>UPDATE!</p>
  
  <h2>The Delimiter thing actually solved my original problem. But I now ended up with a new Error. I'll describe it below along with the implementet changes that solved the first problem.</h2>
  
  <p>I am trying to write a trigger that will log changes in the database to a seperate table. But I keep getting the same error. I have looked at the MYSQL documentation and searched this forum and found a lot of helpfull answers. Trouble is that I now have a piece of SQL code that looks exactly like the answers given in this forum but I still get an error.</p>
  
  <p>The trigger I am trying to use is:</p>
  
  <pre><code>CREATE TRIGGER logInsert AFTER INSERT ON test_table
      FOR EACH ROW
      BEGIN
        INSERT INTO datalog (action, id, timestamp, data1, data2)
        VALUES ('insert', NEW.id, NOW(), NEW.data1, NEW.data2);
      END;
  </code></pre>
  
  <p>The error message I get back is:</p>
  
  <pre><code>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></pre>
  
  <p>I have tried using " instead of single quotes. 
  someone surgested in on of the answers here that you should use backticks, so tried that as well.
  No matter what, the error message is exactly the same.</p>
  
  <p>A friendly soul here posted a fix for my original error. I needed to add DELIMITER to the statement so that it should look like this:</p>
  
  <pre><code>DELIMITER $$
  CREATE TRIGGER logInsert AFTER INSERT ON test_table
      FOR EACH ROW
      BEGIN
        INSERT INTO datalog (action, id, timestamp, data1, data2)
        VALUES ('insert', NEW.id, NOW(), NEW.data1, NEW.data2);
      END$$
  DELIMITER ;
  </code></pre>
  
  <p>This change solved the original error, but also let to a new error.
  The new error is:
   <code>Unknown Coloumn 'id' in table NEW</code></p>
  
  <p>This is the table I'm trying to write to:</p>
  
  <pre><code>CREATE TABLE datalog (
        id   INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        timestamp   TIMESTAMP,
        data1 VARCHAR(255) NOT NULL,
        data2  DECIMAL(5,2) NOT NULL 
  );
  </code></pre>
  
  <p>Hope someone here has an idea of what is wrong.</p>
  
  <p>Kind regards,
  Jonas</p>