title: mysql Multiple Foreign Keys in a Table to the Same Primary Key
body: <p>I have a table <code>user</code> with <code>userID</code> as the primary key. I have another table called <code>Friends</code>. In the <code>Friends</code> table, I have two Users as friends represented by the columns <code>UserID</code> and <code>FrndID</code> where both <code>UserID</code> and <code>FrndID</code> should be a <code>userID</code> in table <code>user</code>.</p>
  
  <p>I want to enforce data integrity. Could I use something like this?</p>
  
  <pre><code>ADD CONSTRAINT `ufd_users_fk` FOREIGN KEY (`userId`, `friendId`)
  REFERENCES `users` (`userId`, `userId`) ON DELETE CASCADE ON UPDATE CASCADE;
  </code></pre>
  
  <p>I want to know is <code>REFERENCES</code>users<code>(</code>userId<code>,</code>userId<code>)</code> referencing a column multiple times correctly? The reason I am not creating 2 separate constraints, is that both users must exist in table <code>user</code>.</p>