title: Create different format for a table
body: <p>I have a table with over 500 columns, dynamically created and named by the user. New columns can be created by the user, but none can be deleted.</p>
  
  <p>I was given the task to program a keyword search that searches through all columns for a specific string, and returns the ID of that record. As you can imagine, the query currently looks something like:</p>
  
  <pre><code>SELECT form_id FROM table_name WHERE col1 LIKE '%str%' OR col2 LIKE '%str%' or col3 LIKE '%str%'.. etc.
  </code></pre>
  
  <p>It is unbelievably slow. To combat this, I'm trying to create another table, where this data is stored in a different format like this:</p>
  
  <pre><code>form_id, col_name, value
  
  1, 'col2', 'some random value'
  1, 'col1', 'another random value'
  </code></pre>
  
  <p>And then searching using: </p>
  
  <pre><code>SELECT id FROM new_table_name WHERE value LIKE '%str%'
  </code></pre>
  
  <p>I can export all the data and format it, and insert it into the new table. But how would I go about keeping the new table updated? Is it possible to have triggers that automatically insert/update the new table when the original one is modified? Even though I don't know the column names before hand?</p>