INSERT语句与FOREIGN KEY约束冲突 [英] INSERT statement conflicted with the FOREIGN KEY constraint

查看:1427
本文介绍了INSERT语句与FOREIGN KEY约束冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我在数据库中插入数据时遇到了一些问题。错误描述如下: -



  INSERT 语句冲突   FOREIGN   KEY  约束   FK_Student_Resource。发生冲突  数据库   SusanneDB table    dbo.Resource '  RESOURCEID'
声明已被终止。







请向我推荐或关于我的错误的指导。



感谢高级...

解决方案

从那个小的,我们不能给你任何确切的代码帮助:但错误非常明确。



ResourceId与另一个表存在外键关系,该表不包含您尝试插入的ID 。首先在Resource表中插入值,或者检查并更正你在resourceID中插入的值

嗨亲爱的,



这个问题的根本原因是在将数据插入到具有0 / null值的主键列值的外键的表中。在您的情况下,资源Id具有0或null并且它被插入到具有外键的表中。



解决方案:1)您必须应用多个检查/验证根据您的需要,在UI上弹出一个有效的错误信息。

2)跟踪你为什么没有获得主键值。如果使用MVC或WPF,问题可能出现在绑定中。


Dear sir,

I have some problem when inserted data in the database.The error should be described as follows :-

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Student_Resource". The conflict occurred in database "SusanneDB", table "dbo.Resource", column 'ResourceId'.
The statement has been terminated.




please suggest to me or guidelines about my error.

thanks in advanced...

解决方案

From that little, we can't give you any exact code help: but the error is pretty explicit.

ResourceId is in a foreign key relationship with another table, which does not contain the ID you are trying to insert. Insert the value in the Resource table first, or check and correct the value you are inserting in resourceID


Hi Dear,

Root cause of this issue is that while inserting data into table having foreign key with 0/null value of primary key column value. In your case resource Id is having either 0 or null and it is being inserted into table having foreign key.

Solution: 1) You have to apply multiple checks/validations according to your need and pop up a valid error message on UI.
2) Trace why you are not getting primary key value. Problem can be in bindings if MVC or WPF used.


这篇关于INSERT语句与FOREIGN KEY约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆