disable cascade失败,老老实实 先外键后主键

Applies to:

Oracle Database - Enterprise Edition - Version 11.2.0.3 and later
Information in this document applies to any platform.

Symptoms

Trying to disable constraints on parent table gives error ORA-2297.


ORA-2297: cannot disable constraint (string.string) - dependencies exist
  Cause: an alter table disable constraint failed because the table has foreign keys that are dependent on this constraint.
  Action: Either disable the foreign key constraints or use disable cascade


Then try to drop? disable  with cascade clause and get error:

ALTER TABLE NAME DISABLE PRIMARY KEY CASCADE

ORA-02433: cannot disable primary key - primary key not defined for table

Changes

Cause

ORA-02433: cannot disable primary key - primary key not defined for table

Indicates no primary key, but unique constraint on child table.


 

Solution

Disable the constraint directly on child table first, then disable on parent table.

Check the constraint on each with following sql:

SELECT p.table_name "Parent Table", c.table_name "Child Table",
  p.constraint_name "Parent Constraint", c.constraint_name "Child Constraint"
  FROM user_constraints p
  JOIN user_constraints c ON(p.constraint_name=c.r_constraint_name)
  WHERE (p.constraint_type = 'P' OR p.constraint_type = 'U')
  AND c.constraint_type = 'R'
  AND p.table_name = UPPER('&table_name');

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐