oracle完整性约束 [英] oracle integrity constraint

查看:59
本文介绍了oracle完整性约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用Oracle.

This is my first time using Oracle.

我手动将一些东西插入数据库:

I inserted something into the db manually:

insert into ATTR_TYPE_VALUE (ATTR_TYPE_ID, VALID_VALUE, CREATED_BY) 
(select ATTR_TYPE_ID, 'Ad', 2 from ATTR_TYPE where VALUE = 'ind')

我收到以下错误:

在第1行出现错误:ORA-02291:完整性约束 (LO.ATTR_TYPE_VALUE_FK02)已违反-找不到父键

ERROR at line 1: ORA-02291: integrity constraint (LO.ATTR_TYPE_VALUE_FK02) violated - parent key not found

这是我在研究中发现的:

Here is what I found upon research:

对于插入语句,当您尝试插入没有外键约束定义的匹配父级的子级时,此ORA-02291错误很常见.在这种情况下,您需要将父行添加到表中,然后重新插入子表行.

For an insert statement, this ORA-02291 error is common when you are trying to insert a child without a matching parent, as defined by a foreign key constraint. In that case, you need to add the parent row to the table and then re-insert your child table row.

这是否意味着ATTR_TYPE表中不存在VALUE='ind'?

Does this mean that the VALUE='ind' does not exist in the ATTR_TYPE table?

推荐答案

ATTR_TYPE_VALUE_FK02定义了哪些列,您引用的是哪些表和列?

What columns is ATTR_TYPE_VALUE_FK02 defined on and what tables and columns are you referencing?

SELECT fk_columns.table_name,
       fk_columns.column_name,
       fk_columns.position,
       pk_columns.table_name,
       pk_columns.column_name,
       pk_columns.position
  FROM all_constraints fk_constraint,
       all_cons_columns fk_columns,
       all_cons_columns pk_columns
 WHERE fk_constraint.owner             = 'LO'
   AND fk_constraint.constraint_name   = 'ATTR_TYPE_VALUE_FK02'
   AND fk_constraint.owner             = fk_columns.owner
   AND fk_constraint.constraint_name   = fk_columns.constraint_name
   AND fk_constraint.r_owner           = pk_columns.owner
   AND fk_constraint.r_constraint_name = pk_columns.constraint_name

这篇关于oracle完整性约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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