INSERT 语句与 FOREIGN KEY 约束冲突

编程入门 行业动态 更新时间:2024-10-22 16:49:58
本文介绍了INSERT 语句与 FOREIGN KEY 约束冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

错误:System.Data.SqlClient.SqlException:INSERT 语句与 FOREIGN KEY 约束FK__Item__order__3AE27131"冲突.冲突发生在数据库pmall"、表dbo.ItemSaved"、列id"中.

Error: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Item__order__3AE27131". The conflict occurred in database "pmall", table "dbo.ItemSaved", column 'id'.

这是我的桌子:

  • id
  • ItemID(在此表中设置为 Item.id 的 FK)
  • ...等

这是我的插入语句:

insert into ItemSavedUnits (ItemID, name, Price) select ItemID, name,Price from ItemUnits where ItemID = 92439

我真的不明白为什么如果我对与 Item.ItemID 和 ItemUnits 相关的 ItemSavedUnits.ItemID 的 FK 约束根本没有约束,为什么我在插入 ItemSavedUnits 时遇到问题.我尝试插入的 ItemID 确实存在于 Item 表中.

I don't really understand why if I a FK constraint on ItemSavedUnits.ItemID that is related to Item.ItemID and ItemUnits has no constraints at all why I'm getting a problem inserting into ItemSavedUnits. The ItemID I'm tryign to insert does exist in the Item table.

推荐答案

您确定 ItemId 92439 存在于 Item 表中,而不仅仅是 ItemUnits 中吗?

Are you absolutely sure that ItemId 92439 exists in the Item table, and not just in ItemUnits?

您的 select 语句是否返回 null?

Is your select statement returning null?

更多推荐

INSERT 语句与 FOREIGN KEY 约束冲突

本文发布于:2023-10-29 03:40:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   冲突   INSERT   KEY   FOREIGN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!