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