Truncate table in Oracle getting errors

后端 未结 9 1287
忘了有多久
忘了有多久 2021-02-02 08:11

I got the problem is when I run following command in Oracle, I encounter the error.

Truncate table mytable;

Errors:

         


        
9条回答
  •  长情又很酷
    2021-02-02 08:55

    this page offers a very good solution ...

    ORA-02266: unique/primary keys in table referenced by enabled foreign keys

    I'm here copying from it the Solution:

    • Find the referenced ENABLED foreign key constraints and disable them.
    • truncate/delete from the table .
    • using any text editor .. just change disable to enable in the output you get from the query , then run it.

      select 'alter table '||a.owner||'.'||a.table_name||' disable constraint '||a.constraint_name||';'
      from all_constraints a, all_constraints b
      where a.constraint_type = 'R' and a.status='ENABLED'
      and a.r_constraint_name = b.constraint_name
      and a.r_owner  = b.owner
      and b.table_name = upper('YOUR_TABLE');
      

提交回复
热议问题