title: Automatically generate SQL INSERT statements with data that respect database constraints
body: <p>Here is a simple situation. (My apologies my SQL is quite rusty.)</p>
  
  <p>(I am using MySQL and Java but it should not matter too much.)</p>
  
  <p>Let's say I have two tables. </p>
  
  <p>Here is a simple SQL statement:</p>
  
  <p>A:</p>
  
  <pre><code>insert into patient (patient_id) values (16)
  </code></pre>
  
  <p>Now there is another table person, which has a person_id and that has to be constrained to match patient_id.</p>
  
  <p>B:</p>
  
  <pre><code>CONSTRAINT `person_id_for_patient` FOREIGN KEY (`patient_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE)
  </code></pre>
  
  <p>What I am looking for is some pre-built tool, solution, etc., that might allow one to expand an insert statement such as A in order to satisfy constraints automatically.</p>
  
  <p>In other words, that would automatically expand A into:</p>
  
  <pre><code>insert into person (person_id) values (16)
  insert into patient (patient_id) values (16)
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thank you
  Misha</p>