在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误

SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM

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

有时候对应的中文错误提示为:ORA-02266: 表中的唯一/主键被启用的外部关键字引用,一般出现这个错误,是因为表中的主键被其它表的外键所引用,导致删除数据时出错。


此时,你可以通过下面脚本查看一下涉及该表主键的外键约束信息。

as org_table_name,
as org_constraint_name,
as org_constriant_type,
as org_colun_name,
as ref_table_name,
as ref_constraint_type,
as ref_constraint_name,
as ref_column_name
from dba_constraints  c1,
  10:        dba_constraints  c2,
  11:        dba_cons_columns n1,
  12:        dba_cons_columns n2
'OWNER_NAME'
'TABLE_NAME'
and n1.constraint_name = c1.constraint_name
and n1.owner = c1.owner
'R'
and c2.r_constraint_name = c1.constraint_name
and n2.owner = c2.owner
and n2.constraint_name = c2.constraint_name;

相关文章:

  • 2021-07-09
  • 2021-11-30
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-09-04
  • 2021-10-15
猜你喜欢
  • 2021-09-17
  • 2022-12-23
  • 2021-12-16
  • 2021-07-25
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案