ORA-02266错误处理

truncate一张表,报ORA-02266错误。


SQL> truncate table WRM$_DATABASE_INSTANCE;
truncate table WRM$_DATABASE_INSTANCE
               *
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys


禁止主键,执行truncate语句清除表WRM$_DATABASE_INSTANCE内容

SQL> alter table WRM$_DATABASE_INSTANCE disable primary key;
alter table WRM$_DATABASE_INSTANCE disable primary key
*
ERROR at line 1:
ORA-02297: cannot disable constraint (SYS.WRM$_DATABASE_INSTANCE_PK) -
dependencies exist
SQL> alter table WRM$_DATABASE_INSTANCE disable primary key cascade;
Table altered.
SQL> truncate table WRM$_DATABASE_INSTANCE;
Table altered.
SQL> alter table WRM$_DATABASE_INSTANCE enable primary key;


note1:

[oracle@server ~]$ oerr ora 02297

02297, 00000,"cannot disable constraint (%s.%s) - dependencies exist"

// *Cause: an alter table disable constraint failed becuase the table has

//      foriegn keys that are dpendent on this constraint.

// *Action: Either disable the foreign key constraints or use disable cascade


note2:

使用cascade参数同时将disable子表的外键;那么在enble父表主键时,同时需要enble子表外键。

当enable子表的外键时,可能存在如下报错

SQL> ALTER TABLE  WRM$_SNAPSHOT ENABLE CONSTRAINT WRM$_SNAPSHOT_FK;

ALTER TABLE  WRM$_SNAPSHOT ENABLE CONSTRAINT WRM$_SNAPSHOT_FK

                                            *

ERROR at line 1:

ORA-02298: cannot validate (SYS.WRM$_SNAPSHOT_FK) - parent keys not found

未找到父项关键字所以报错,删除主表中多余数据,保证主表与子表一致然后enable外键。


你可能感兴趣的:(ORA-02266,ORA-02298,ORA-02297)