我有一个不会启用的引用约束,即使引用的值确实在引用的表中.我仔细查看了约束脚本和两个表中的拼写.
当我尝试启用约束时,返回的错误是"未找到父键".我物理地比较了数据,并且所需的值确实在引用的表中.
引用的列设置为主键,并且已启用.
涉及的过程涉及通过dblink从另一个模式/数据库加载/传输数据.
在用于数据传输的源表中,存在确实启用的类似约束.
由于数据敏感性,无法真正发布数据,只是希望我能得到一些有待进一步检查的想法.
任何想法或建议表示赞赏.
约束代码:
ALTER TABLE SR2.LOG ADD (
CONSTRAINT FF1
FOREIGN KEY (NOTCH_ID)
REFERENCES SR2.NOTCH (ID)
DISABLE NOVALIDATE);
Run Code Online (Sandbox Code Playgroud)
小智 5
有一个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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |