title: Foreign Key to non-primary key
body: <p>I have a table which holds data, and one of those rows needs to exist in another table. So, I want a foreign key to maintain referential integrity.</p>
  
  <pre><code>CREATE TABLE table1
  (
     ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
     AnotherID INT NOT NULL,
     SomeData VARCHAR(100) NOT NULL
  )
  
  CREATE TABLE table2
  (
     ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
     AnotherID INT NOT NULL,
     MoreData VARCHAR(30) NOT NULL,
  
     CONSTRAINT fk_table2_table1 FOREIGN KEY (AnotherID) REFERENCES table1 (AnotherID)
  )
  </code></pre>
  
  <p>However, as you can see, the table I foreign key to, the column isn't the PK. Is there a way to create this foreign key, or maybe a better way to maintain this referential integrity?</p>