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?
Error:
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)
SQL 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)
Tables:
Your
idRaprortoMobile
is12
, not1236
.1236
isidRapporto
. Check what column your foreign key points to, and you'll see it's the issue.