title: SQL add Foreign key constraint with check
body: <p>I have the following query which is adding contraint.
  but in order to add, i want to check if this key has already been used or not?</p>
  
  <pre><code>ALTER TABLE HL7_MessageHierarchy  
   ADD CONSTRAINT fk_vMessageType FOREIGN KEY (vMessageType) 
         REFERENCES HL7_MessageType(vMessageType);
  </code></pre>
  
  <p>for example. if i have to add a column, i can easily check if the table exists in sysobjects and its respective column exists in syscolumns.</p>
  
  <p>Is it possible to use the query multiple times without GO and without making any error indeed? if yes then how ???</p>
  
  <p>[EDIT]</p>
  
  <p>I don't know why my browser not allowing me to add comments so i am adding to Edit.</p>
  
  <p>I want to check if there exists any foreign key with same name. so if there is no data even then the query can make problem because the key may already be existing. I want to run the above script clean (ofcourse resident data does matter but that is perhaps a straight forward check?)
  [EDIT]</p>
  
  <p>my bad, i must have known that version is important... I believe its 2005... (will love to know if someone can tell for other versions too)</p>