title: Foreign Key constraint failure and error mesage when inserting values
body: <p>Hopefully someone can help. I have created two tables Customer and Order as follows;</p>
  
  <pre><code>CREATE TABLE Customer
  CustomerID int NOT NULL PRIMARY KEY
  CustomerName varchar(25)
  </code></pre>
  
  <p>The other columns in Customer table are not relevant to my question, so I will not include them here. My CustomerID numbers are from 1 through to 15, all unique.</p>
  
  <p>The second table I created is Orders as follows</p>
  
  <pre><code>CREATE TABLE Orders
  OrderID smallint NOT NULL PRIMARY KEY
  OrderDate date NOT NULL
  CustomerID int FOREIGN KEY REFERENCES Customer (CustomerID);
  </code></pre>
  
  <p>My insert values is as follows</p>
  
  <pre><code>INSERT INTO Orders (OrderID, OrderDate, CustomerID)
  VALUES
  (1001, '2008-10-21', 1),
  (1002, '2008-10-21', 8),
  (1003, '2008-10-22', 15),
  (1004, '2008-10-22', 5),
  (1005, '2008-10-24', 3),
  (1006, '2008-10-24', 2),
  (1007, '2008-10-27', 11),
  (1008, '2008-10-30', 12),
  (1009, '2008-11-05', 4),
  (1010, '2008-11-05', 1);
  </code></pre>
  
  <p>When I try to insert my values into the Order table, I get the following error message....</p>
  
  <blockquote>
    <p>Msg 547, Level 16, State 0, Line 1.....The INSERT statement conflicted
    with the FOREIGN KEY constraint "FK__OrderT__Customer__2D27B809". The
    conflict occurred  table "dbo.Customer", column 'CustomerID'. The
    statement has been terminated.</p>
  </blockquote>
  
  <p>The numbers for CustomerID in my Order table, are (1; 1; 2; 3; 4; 5; 8; 11; 12 and 15). Therefore I have checked that all my CustomerID numbers in Order table are also in the Customer table.</p>
  
  <p>So my questions are</p>
  
  <p>1) Has the insert values failed because my CustomerID column in Customer table in NOT NULL and I in error made CustomerID column NULL in Order. </p>
  
  <p>2) If the answer to the above question is yes, then is it possible for me to (a) drop the foreign key on the CustomerID column in Order (b) change the column to NOT NULL and (c) then add the foreign key constraint again to this column and then insert the values again?</p>
  
  <p>It might be easier to drop and re-create the table Order. But I am curious if option 2 would work, re dropping and adding a foreign key on the same column.</p>
  
  <p>Hopefully I am on the right track with why I think the error occurred, feel 
  to correct me if I am wrong.  </p>
  
  <p>Thanks everyone
  Josie  </p>