title: Loop through columns in MySQL trigger
body: <p>Is it possible to loop through the all column names while inside a trigger?</p>
  
  <p>Scenario:
  To log all the columns of a table that have been modified.
  If some values did not change, do not log those ones.</p>
  
  <pre><code>DROP TRIGGER IF EXISTS t_before_update_test;
  DELIMITER $$
  CREATE TRIGGER t_before_update_test
  BEFORE UPDATE ON test
  FOR EACH ROW
  BEGIN
      -- Loop here for all columns, not just col1
      IF OLD.col1 &lt;&gt; NEW.col1 THEN
          INSERT INTO change_logs(
              log_on, user_id,
              table_name, colum_name,
              old_data, new_data
          ) VALUES (
              UNIX_TIMESTAMP(NOW()), '0',
              'test', 'col1',
              OLD.col1, NEW.col1
          );
      END IF;
      -- process looping all columns
      -- col1, col2, ... should be dynamic per loop
  END $$
  </code></pre>
  
  <p>This is working copy example, where I now need to loop through all columns available in OLD or NEW.</p>