title: How to reference two tables in Visual Studio 2012 by adding foreign key?
body: <p>I have a problem adding a foreign key to a table column.
  My tables look this way. I need to reference <code>ContactOwnerId</code> from <code>Contact</code> table to <code>UserId</code> in <code>UserProfile</code> table</p>
  
  <pre><code>CREATE TABLE [dbo].[Contacts] (
      [ContactId] INT            IDENTITY (1, 1) NOT NULL,
      [ContactOwnerId]    INT            NOT NULL,
      [FirstName] NVARCHAR (MAX) NOT NULL,
      [LastName]  NVARCHAR (MAX) NOT NULL,
      [Address]   NVARCHAR (MAX) NOT NULL,
      [City]      NVARCHAR (MAX) NOT NULL,
      [Phone]     NVARCHAR (MAX) NOT NULL,
      [Email]     NVARCHAR (MAX) NOT NULL,
      CONSTRAINT [PK_dbo.Contacts] PRIMARY KEY CLUSTERED ([ContactId] ASC), 
      CONSTRAINT [FK_Contacts_UserProfile] FOREIGN KEY ([UserId]) REFERENCES [Contacts]([ContactOwnerId])
  );
  
  CREATE TABLE [dbo].[UserProfile] (
      [UserId]   INT           IDENTITY (1, 1) NOT NULL,
      [UserName] NVARCHAR (56) NOT NULL,
      PRIMARY KEY CLUSTERED ([UserId] ASC),
      UNIQUE NONCLUSTERED ([UserName] ASC)
  );
  </code></pre>
  
  <p>I added a foreign key, but it seems, not right, because UserId is highlighted, giving error:</p>
  
  <pre><code>SQL71501 :: Foreign Key: [dbo].[FK_Contacts_UserProfile] has an unresolved reference to Column [dbo].[Contacts].[UserId].
  SQL71516 :: The referenced table '[dbo].[Contacts]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column is a computed column, it should be persisted.
  </code></pre>
  
  <p>How do I correctly reference these two tables? Thanks in advance.</p>
  
  <p><strong>EDIT</strong>
  I did like <strong>sgeddes</strong> said. But I get an error, when I try to create a contact. 
  The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Contacts_UserProfile". The conflict occurred in database "ContactAppContext", table "dbo.UserProfile", column 'UserId'.
  The statement has been terminated.</p>
  
  <p>If I remove a foreign key I get no error.</p>
  
  <p>What I want to achieve is, when a user creates contacts, his Id(UserId) could associate with ContactOwnerId, so that contacts could relate to one specific user.</p>