title: UPDATE statement conflicted with the FOREIGN KEY constraint on Sql Server 2014
body: <p>Hi guys I have to update a foreign key, on a server sql 2014, but when I run the code below I have the following error, how can fix it?</p>
  
  <p><strong>Error:</strong></p>
  
  <p><em>Msg 3621, Level 0, State 0.
  The statement has been terminated.
  Msg 547, Level 16, State 0.
  The UPDATE statement conflicted with the FOREIGN KEY constraint "fk_restirizione_idrapportomobile". The conflict occurred in database "db", table "dbo.RapportoMobile", column 'IdRapportoMobile'. (Line 1)</em></p>
  
  <p><strong>SQL Code:</strong></p>
  
  <pre><code>UPDATE risorsarapportomobile 
  SET    risorsarapportomobile.idrapportomobile = 1236 
  WHERE  risorsarapportomobile.idrisorseumane IN (SELECT 
         risorseumane.idrisorseumane 
                                                  FROM   risorsarapportomobile 
                                                         INNER JOIN risorseumane 
                                                                 ON 
         risorseumane.idrisorseumane = 
         risorsarapportomobile.idrisorseumane 
         WHERE  risorsarapportomobile.idrapportomobile IS NULL 
         AND CONVERT(VARCHAR(10), '26-06-2018', 105) = 
             CONVERT(VARCHAR(10), risorseumane.data, 105) 
         AND risorseumane.idcantiere = 158) 
  </code></pre>
  
  <p><strong>Tables:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/dSfxG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dSfxG.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/q5aP2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q5aP2.png" alt="enter image description here"></a></p>