UPDATE语句与Sql Server 2014上的外键约束冲突

UPDATE语句与Sql Server 2014上的外键约束冲突,sql,sql-server,Sql,Sql Server,大家好,我必须在SQLS2014服务器上更新一个外键,但是当我运行下面的代码时,我出现了以下错误,如何修复它 错误: UPDATE risorsarapportomobile SET risorsarapportomobile.idrapportomobile = 1236 WHERE risorsarapportomobile.idrisorseumane IN (SELECT risorseumane.idrisorseumane

大家好,我必须在SQLS2014服务器上更新一个外键,但是当我运行下面的代码时,我出现了以下错误,如何修复它

错误:

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) 
消息3621,级别0,状态0。 声明已终止。 消息547,16级,状态0。 UPDATE语句与外键约束“fk_restirizione_idrapportomobile”冲突。冲突发生在数据库“db”、表“dbo.reportomobile”、列“IdRapportoMobile”中。(第1行)

SQL代码:

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) 
表格:

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) 


由于设置后只有一个字段,并且由于错误消息,我们可以推断

要输入的值1236不在dbo.reportomobile.IdRapportoMobile中,它是外键的目标


首先将值添加到该列,然后运行更新。

因为设置后只有一个字段,并且由于错误消息,我们可以推断

要输入的值1236不在dbo.reportomobile.IdRapportoMobile中,它是外键的目标



首先将值添加到该列,然后运行更新。

您的
idraprotomobile
12
,而不是
1236
<代码>1236是
idraperto
。检查外键指向哪个列,您就会发现问题所在。

您的
idraprotomobile
12
,而不是
1236
<代码>1236是
idraperto
。检查外键指向哪个列,就会发现问题所在。

值1236必须已经位于外键指向的任何表中。如果提取外键定义,它将告诉您该表是什么。外键是数据库中非常基本的概念-您应该了解它们FK的存在是有原因的-不要放弃它!您正在尝试更新引用表
reportomobile
的表中的键。这意味着你的钥匙不匹配。如果在
reportomobile
上有一个更新级联约束,那么更新主表将修复它。但必须先在这里完成我们需要你的FK代码。您能找到此FK(在SSMS对象资源管理器上,展开(+图标)risorsarapportomobile,展开Keyes,右键单击“FK_restirizione_idrapportomobile”,修改)并发布其代码吗?值1236必须已位于外键指向的任何表中。如果提取外键定义,它将告诉您该表是什么。外键是数据库中非常基本的概念-您应该了解它们FK的存在是有原因的-不要放弃它!您正在尝试更新引用表
reportomobile
的表中的键。这意味着你的钥匙不匹配。如果在
reportomobile
上有一个更新级联约束,那么更新主表将修复它。但必须先在这里完成我们需要你的FK代码。你能找到这个FK(在SSMS对象资源管理器上,展开(+图标)risorsarapportomobile,展开Keyes,右键单击“FK_restirizione_idrapportomobile”,修改)并发布它的代码吗?我怎么知道不用先选择就要更新哪些行?不确定你的顺序。您必须在dbo.reportomobile中插入IdRapportoMobile=1236的行,然后才能执行更新。表reportomobile中已存在值1236,我只需使用该值更新另一个表。1236必须位于IdRapportoMobile列中,非报告员移动设备如果idrapportomobile以报告员移动设备而不是idrapportomobile为目标,则您的触发器错误。否则,您可能应该使用12而不是1236,因为这是您提到的行的对应值。如果不先选择,我如何知道要更新哪些行?不确定您的意思是什么顺序。您必须在dbo.reportomobile中插入IdRapportoMobile=1236的行,然后才能执行更新。表reportomobile中已存在值1236,我只需使用该值更新另一个表。1236必须位于IdRapportoMobile列中,非报告员移动设备如果idrapportomobile以报告员移动设备而不是idrapportomobile为目标,则您的触发器错误。否则,您可能应该使用12而不是1236,因为这是您提到的行的对应值。