title: how to safety check a composite key before assigning it as a foreign key?
body: <p>So normally when one wants to declare a foreign key on a populated table, they'll first make sure that the foreign table has all the values contained in the table where the foreign key is being created.</p>
  
  <pre><code>    select * from myschema.Orders
          where ProductID not in
              (select ProductID from myschema.Products);
  </code></pre>
  
  <p>Should any records be returned from the above query, then the DBA will first have to deal with those before setting a foreign key. But what if the <code>Products</code> table contained a composite foreign key? How would the above check be done if the Products table had both the fields <code>ProductID</code> and (For example) <code>BatchNumber</code> as a primary key?</p>
  
  <p>This is assuming the <code>Orders</code> table also has both fields.</p>