Oracle cascade operations

Source: Internet
Author: User

Oracle cascade operations

When you add a foreing key constraint, you can also specify the cascade operation type, which is mainly used to determine how to process the foreign key fields in the subtable When deleting a record in the (on delete) Appendix, there are three types of reference.

Cascade
This keyword is used to indicate that when you delete data from referenced columns in the primary table, the value of the corresponding application column in The subtable is set to null. In this case, the reference column in The subtable must support null values.
Set null
This keyword is used to set the value of the referenced column in The subtable to null when the data in the referenced column in the primary table is deleted. In this case, the application column in the sub-table must support null values.
Not action
This keyword is used to indicate that when the referenced data in the primary table is deleted, the operation is prohibited if the referenced column type of the child table contains this value. This option is used by default.

The specific operations are as follows:
SQL> create table stuclass (
2 cid number (4) primary key,
3 cname varchar2 (40 ),
4 num number (4)
5 );
The table has been created.
SQL> create table stu (
2 sid number (4 ),
3 scode varchar (10 ),
4 sname varchar (20 ),
5 cid number (4) references stuclass (cid) on delete set null
6 );
The table has been created.
SQL> insert into stuclass values (1, 'oracle ', 35 );
One row has been created.
SQL> insert into stu values (1, 's001 ', 'aaa', 1 );
One row has been created.
SQL> delete stuclass where cid = 1;
One row has been deleted.
SQL> select * from stuclass;
Unselected row
SQL> select * from stu;
SID SCODE SNAME CID
--------------------------------------------------
1 s001 aaa
SQL>

Oracle cascade operations

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.