虚位以待(AD)
虚位以待(AD)
首页 > 数据库 > Oracle数据库 > oracle在操作主、外键需要注意的ORA-02449、ORA-02298

oracle在操作主、外键需要注意的ORA-02449、ORA-02298
类别:Oracle数据库   作者:码皇   来源:互联网   点击:

oracle在操作主、外键需要注意的ORA-02449、ORA-02298解决 做的项目很少加外键,今天碰到了有外键的系统刷数据有两个问题,特记录一下。SQL> drop table test1 purge;表已删除。SQL> drop table tes
oracle在操作主、外键需要注意的ORA-02449、ORA-02298解决         做的项目很少加外键,今天碰到了有外键的系统刷数据有两个问题,特记录一下。   SQL> drop table test1 purge;   表已删除。 SQL> drop table test2 purge; 表已删除。   SQL> create table test1 as select * from dba_objects where object_id is not null; 表已创建。 SQL> alter table test1       add constraint pk_t1_object_id primary key(OBJECT_ID); 表已更改。 SQL> create table test2 as select * from test1; 表已创建。 SQL> alter table TEST2   2    add constraint fk_t2_object_id foreign key (OBJECT_ID)   3    references test1 (OBJECT_ID); 表已更改。 SQL> drop table test1; drop table test1            * 第 1 行出现错误: ORA-02449: 表中的唯一/主键被外键引用   SQL> drop table test1 cascade  constraint;           SQL> drop table test1 purge; drop table test1 purge            * 第 1 行出现错误: ORA-00942: 表或视图不存在 SQL> drop table test2 purge; 表已删除。 SQL> create table test1 as select * from dba_objects where object_id is not null; 表已创建。   SQL> alter table test1       add constraint pk_t1_object_id primary key(OBJECT_ID); 表已更改。 SQL> create table test2 as select * from dba_objects; 表已创建。   SQL> update test2 set object_id = 99999 where object_id is null; 已更新 1 行。 SQL> commit; 提交完成。   SQL> alter table TEST2       add constraint fk_t2_object_id foreign key (OBJECT_ID)       references test1 (OBJECT_ID);   add constraint fk_t2_object_id foreign key (OBJECT_ID)                  * 第 2 行出现错误: ORA-02298: 无法验证 (TEST.FK_T2_OBJECT_ID) - 未找到父项关键字   找出从表的记录不在主键中 SQL> select count(*) from test2 t2   2   where not exists   3   (select 1 from test1 t1 where t1.object_id = t2.object_id);   COUNT(*) ----------          3   表已删除。
相关热词搜索: oracle 操作 需要注意