gpt4 book ai didi

甲骨文11g : Confounding constraint

转载 作者:行者123 更新时间:2023-12-02 06:40:15 25 4
gpt4 key购买 nike

我有一个无法启用的引用约束,即使引用的值确实位于引用的表中。我仔细检查了约束脚本和两个表中的拼写。

当我尝试启用约束时,返回的错误是“找不到父键”。我物理比较了数据,所需的值确实在引用的表中。

引用的列设置为主键并且已启用。

所涉及的过程涉及通过 dblink 从另一个模式/数据库加载/传输数据。

在数据传输的源表中,确实启用了类似的约束。

由于数据敏感性,无法真正发布数据,只是希望我能得到一些进一步检查的想法。

任何想法或建议表示赞赏。

约束代码:

  ALTER TABLE SR2.LOG ADD (
CONSTRAINT FF1
FOREIGN KEY (NOTCH_ID)
REFERENCES SR2.NOTCH (ID)
DISABLE NOVALIDATE);

最佳答案

Oracle 有一个内置的解决方案可以解决这个问题。您可以使用 ALTER TABLE 的 EXCEPTIONS 子句:

  -- parent table
create table t1 (col1 number primary key);

insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
commit;

-- child table
create table t2 (col1 number);

insert into t2 values (1);
insert into t2 values (2);
insert into t2 values (3);
insert into t2 values (4); -- bad data
commit;

-- You create a table for the exceptions
create table excepts (row_id rowid,
owner varchar2(30),
table_name varchar2(30),
constraint varchar2(30));

-- you still get error
alter table t2 add constraint f2 foreign key (col1) references t1
exceptions into excepts ;

-- but bad data will be here
-- please notice its 'ROW_ID' from the second table
select t2.*
from t2,
excepts
where t2.rowid = excepts.row_id;

关于甲骨文11g : Confounding constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16866303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com