title: Constraint based on a FK relationship
body: <p>Structure of two tables with fields that are of importance:</p>
  
  <pre><code>TableA: Id (PK), Type
  TableB: Id (PK), TableAId (FK), ReferenceId (Self-reference key)
  </code></pre>
  
  <p>I need to have a constraint which will say:</p>
  
  <p>TableB ReferenceId column CAN and MUST contain a value ONLY IF TableAId value points to a record whose Type value > 1.</p>
  
  <p>How can I do this?</p>