title: Mysql Triggers: Track changes
body: <p>I don't know if this is possible, but I want to track changes of the table 1.</p>
  
  <p>In the database the following two tables exists:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `db`.`table1` (
    `idtable1` INT NOT NULL AUTO_INCREMENT,
    `A` VARCHAR(45) NULL,
    `B` VARCHAR(45) NULL,
    `C` VARCHAR(45) NULL,
    PRIMARY KEY (`idtable1`))
  ENGINE = InnoDB
  
  
  CREATE TABLE IF NOT EXISTS `db`.`table2history` (
    `idtable2history` INT NOT NULL AUTO_INCREMENT,
    `columnName` ENUM('A', 'B', 'C') NULL,
    `columnPrimaryKey` INT NULL,
    `columnNewValue` VARCHAR(45) NULL,
    `changetimestamp` DATETIME NULL,
    PRIMARY KEY (`idtable2history`))
  ENGINE = InnoDB
  </code></pre>
  
  <p><strong>If the following instructions is executed:</strong></p>
  
  <pre><code>UPDATE table1 SET A="ABC", B="XYZ" WHERE  idtable1=50;
  </code></pre>
  
  <p><strong>The Trigger "BEFORE UPDATE" should execute:</strong></p>
  
  <pre><code>INSERT INTO table2history (idtable2history, columnName, columnPrimaryKey, columnNewValue, changetimestamp)
  VALUES (NULL, "A", "50", "ABC", NOW());
  
  INSERT INTO table2history (idtable2history, columnName, columnPrimaryKey, columnNewValue, changetimestamp)
  VALUES (NULL, "B", "50", "XYZ", NOW());
  </code></pre>
  
  <p><strong>If the following instructions is executed:</strong></p>
  
  <pre><code>UPDATE table1 SET A="123", B="456", C="789" WHERE  idtable1=20;
  </code></pre>
  
  <p><strong>The Trigger "BEFORE UPDATE" should execute:</strong></p>
  
  <pre><code>INSERT INTO table2history (idtable2history, columnName, columnPrimaryKey, columnNewValue, changetimestamp)
  VALUES (NULL, "A", "20", "123", NOW());
  
  INSERT INTO table2history (idtable2history, columnName, columnPrimaryKey, columnNewValue, changetimestamp)
  VALUES (NULL, "B", "20", "456", NOW());
  
  INSERT INTO table2history (idtable2history, columnName, columnPrimaryKey, columnNewValue, changetimestamp)
  VALUES (NULL, "C", "20", "789", NOW());
  </code></pre>
  
  <p><strong>Do you know an intelligent solution for this problem?</strong></p>