火鸟数据库插入数据 [英] firebird database insert data

查看:254
本文介绍了火鸟数据库插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人


Dear All


public void insertdataintosql(string sgd_id, string sgd_sgp_id, string sgd_hed_id, string sgd_type, i got this error 

violation of FOREIGN KEY constraint "FK_SAL_SGD_SAL_PTG" on table "SAL_SGD"
Foreign key reference target does not exist

how to resolve this one

推荐答案

从约束的命名 FK_SAL_SGD_SAL_PTG 我猜想有一个表 SAL_PTG .
该表包含允许您用作 SAL_SGD.SGD_PTG_ID 的值的键.因此,在 SAL_SGD.SGD_PTG_ID 中输入值之前,
您必须将其输入 SAL_PTG .

但这只是一个猜测,假设 FK_SAL_SGD_SAL_PTG 显示了外键的源和目标表.

问候
Michel
From the naming of the constraint FK_SAL_SGD_SAL_PTG I''d guess that there is a table SAL_PTG.
This table contains the keys which you are allowed to use as values for SAL_SGD.SGD_PTG_ID. So before entering a value into SAL_SGD.SGD_PTG_ID,
you have to enter this into SAL_PTG.

But this is just a guess, assuming that FK_SAL_SGD_SAL_PTG shows source and destination table of foreign key.

regards
Michel


它与错误消息所言完全相同:表SAL_SGD中的一个或多个列具有预定的键约束(名称为FK_SAL_SGD_SAL_PTG),它引用了另一个表的键列.除非另一张表中存在具有相同键的行,否则您不能在SAL_SGD中插入行.

由于您尚未发布约束的定义,因此我无法说出哪些列是包含这些键的列,而且我也不知道它所引用的其他表.因此,由您决定在th表的属性中查找此定义,并且应确保在您的代码中此关系在任何时候都不会中断.您必须确保在另一个表中引用的那些值确实存在.

在您问之前:删除约束是一个非常糟糕的主意.确实可以使错误消失,但是然后就不再保证这两个表之间的关系的完整性,这肯定会导致应用程序的意外行为.
It''s exactly as the error message says: One or more columns in your table SAL_SGD have a foregn key constraint (with the name FK_SAL_SGD_SAL_PTG) that refers to key columns of another table. You cannot insert a row into SAL_SGD unless a row with the same keys exists in the other table.

Since you have not posted the definition of the constraint, I cannot say which columns are the ones that contain those keys and I also don''t know what other table it refers to. Therefore it''s up to you to look up this definition in the properties of th table and bthen make sure in your code that this relation is not broken at any time. You must make sure that those values you refer to in the other table really exist.

And before you ask: It''s a very bad idea to remove the constraint. This would indeed let the error disappear, but then the integrity of the relation between those two tables is not guaranteed anymore, wich will certainly lead to unexpected behavior of the application.


这篇关于火鸟数据库插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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