Oracle 12C--cascade operation for TRUNCATE

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.