title: Conditional Foreign Key to multiple tables
body: <p>I have a table which contains two type of data, either for Company or Employee.</p>
  
  <p>Identifying that data by either 'C' or 'E' &amp; a column storing primary key of it.</p>
  
  <p>So how can I give foreign key depending on data contained &amp; maintain referential integrity dynamically.</p>
  
  <pre><code>id | referenceid  | documenttype 
  -------------------------------
  1  | 12           | E 
  2  | 7            | C 
  </code></pre>
  
  <p>Now row with id 1 should reference Employee table with pk 12 &amp; row with id 2 should reference Company table with pk 7.</p>
  
  <p>Otherwise I have to make two different tables for both.
  Is there any other way to accomplish it.</p>