相关疑难解决方法(0)

INSERT语句与FOREIGN KEY约束冲突

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

这是我的表:

ItemSavedUnits

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

这是我的插入声明:

insert into ItemSavedUnits (ItemID, name, Price)
select ItemID, name,Price
from ItemUnits where ItemID = 92439 
Run Code Online (Sandbox Code Playgroud)

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

t-sql sql-server sql-server-2008

13
推荐指数
1
解决办法
4万
查看次数

标签 统计

sql-server ×1

sql-server-2008 ×1

t-sql ×1