用truncate断载表数据时,我们一般要先清理子表,再清父表,如果在清理过程中遇到 “ORA-02266: 表中的唯一/主键被启用的外键引用” 报错,那么我们要先停主键,清理数据后再启动
SQL> truncate table dept; ---清理报错
truncate table dept
*
第 1 行出现错误:
ORA-02266: 表中的唯一/主键被启用的外键引用
SQL> alter table dept disable primary key cascade; ---禁用主键被引用
表已更改。
SQL> truncate table dept; ---清理表数据
表被截断。
SQL> alter table dept enable primary key; ----启动主键
表已更改。
引用:
1、ORACLE数据库中的外键约束名都在表user_constraints中可以查到。其中constraint_type='R'表示是外键约束。
2、启用外键约束的命令为:alter table 表名 enable constraint 约束名
3、禁用外键约束的命令为:alter table 表名 disable constraint 约束名
4、然后再用SQL查出数据库中所以外键的约束名:
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/18762014/viewspace-774971/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/18762014/viewspace-774971/