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

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

錯誤概述

表中的唯一/主键被啟用的外部關鍵字引用。

 

錯誤訊息

SQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
02266. 00000 -  "unique/primary keys in table referenced by enabled foreign keys"
*Cause:    An attempt was made to truncate a table with unique or
           primary keys referenced by foreign keys enabled in another table.
           Other operations not allowed are dropping/truncating a partition of a
           partitioned table or an ALTER TABLE EXCHANGE PARTITION.

 

 

 

 

情境說明

下 truncate table 語法出錯,應為主键被子表引用,導致無法直接清空主表資料。

 

解決方案

停用主鍵 -> 清空資料表 -> 啟用主鍵


TRUNCATE TABLE 資料表名;
ALTER TABLE 資料表名 ENABLE PRIMARY KEY;

 

 

參考資料

truncate报ORA-02266错“唯一/主键被启用的外部关键字引用”解决方法

 

創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權,文章歡迎轉載,請註明出處,謝謝~~~