Oracle Cascade Delete

Source: Internet
Author: User

Oracle cascading deletes can be implemented using triggers, but the simplest is to directly establish the primary foreign key relationship of the table and set the cascade Delete for the column.

------created the class table and set the ID field as the primary key.

1 --Create Table2 Create TableCLASS3 (4IdVARCHAR2(2) not NULL,5Class_nameVARCHAR2( -)6 )7 Alter TableCLASS8   Add constraintPk_classPrimary Key(ID)

------created the students table and set the ID field as the primary key, class_id as a foreign key and cascade Delete.

1 --Create Table2 Create TableSTUDENTS3 (4IdVARCHAR2(4) not NULL,5class_idVARCHAR2(2) not NULL,6Stu_nameVARCHAR2( -),7Stu_age Number8 )9 Ten Alter TableSTUDENTS One   Add constraintPk_stuPrimary Key(ID) A  - Alter TableSTUDENTS -   Add constraintFk_stuForeign Key(class_id) the   ReferencesCLASS (ID) on Delete Cascade;

This removes the class ID and the student who belongs to it will be deleted.

------Delete primary Key original key

ALTER TABLE DROP CONSTRAINT Pk_media_user

Oracle Cascade Delete

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.