SQL异常... [英] SQL Exception...

查看:68
本文介绍了SQL异常...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_lms_newreg_lms_Refferal". The conflict occurred in database "SSS_lms", table "dbo.lms_Refferal", column 'Refferal_Id'.
The statement has been terminated.



这是一个例外,我有时会因为有时它可以正常工作而得到它!

我不明白为什么会这样.请提出建议.



this is an exception which i get sometimes only as sometimes it works correctly!

I dont understand why this happen. Please suggest.

推荐答案

发生这种情况的原因是,您必须尝试在表lms_newreg中插入一个值,其中lms_Referal中不存在Refferal_Id.

有时,您尝试为该键插入的值都存在,因此没有错误.但是有时在lms_refferal表中找不到用于此值的值,因此会出现错误.
This happens because, you must be trying to insert a value in table lms_newreg where Refferal_Id that does not exists in lms_Referal.

At times, what you try to insert for that key, the value exists so no error. But sometime the value used for it is not found in the lms_refferal table and thus the error.


外键(FK)是用于建立和强制执行的列或列组合两个表中的数据之间的链接.
现在,我的朋友仔细查看ur表,因为您在输入数据时必须犯错,因为您必须添加的数据不能出现在其他人提供的ur表中,因此请在表格输入时检查ur表或使用组合框或页面加载事件阻止了数据库中所需的列并完成了操作...
没有错误也没有例外,也没有严重的数据输入错误,因为当您的应用程序加载时,数据将已经出现在组合框中

另请阅读参考完整性 [
A foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data in two tables.
Now my friend carefully look at ur tables as ur doin some sort of errors while data entry as the data which u must be addin must not be present in the other table whos reference ur giving so please check out ur tables or use a combobox during form or page load event reterive the desired column from the database and ur done...
no erors no exceptions and no serious data entry errors because the data will already be present in the combobox when ur application loads

also read the Referential Integrity[^]in SQL for better understanding

Do rate my answer once u find it useful

Thanks & Regards
Radix :rose:


这篇关于SQL异常...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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