In previous versions, the parent table could not be truncate directly when there was a foreign key constraint. In 12C, a cascade operation attribute was added to the truncate operation.
If you create a FOREIGN key constraint, use "on Delete Casacde".
Test script:
Sql>drop table child; SQL>drop table parent; SQL>CREATE TABLE parent (ID number primary key); SQL>CREATE TABLE Child (CID number primary key,pid number); SQL>ALTER TABLE child add constraint fk_parent_child foreign key (PID) references the parent (ID) on DELETE cascade; SQL> INSERT into parent values (1); SQL> INSERT into parent values (2); SQL> INSERT INTO child values (1,1); SQL> INSERT INTO child values (2,1); SQL> INSERT INTO child values (3,2); SQL>commit; SQL>SelectA.id,b.cid,b.pid fromParent A, child BwhereA.id=B.pid; ID CID PID---------- ---------- ----------1 1 1 1 2 1 2 3 2SQL>
Test results for 11GR2:
Sql> TRUNCATE TABLE parent cascade;truncate table Parent Cascade *1: ORA- 03291: Invalid truncate option- missing STORAGE keywordsql>
Test results for 12C:
Sql> TRUNCATE TABLE parent cascade; Table truncated. SQL>
Oracle 12C--cascade operation for TRUNCATE