????????On delete cascade
???????????????????????????????????????鷳???????????????????????ζ???????????????????????????????????On delete cascade?????????“??????????????????????”??????????????????????????????
????????on delete cascade??????????????????????????????
????SQL> alter table child add constraint FK_CHILD_PRIM foreign key(v_id) references prim(v_id) on delete cascade;
????Table altered
?????????
SQL> delete prim where v_id=2;
1 row deleted
SQL> select * from prim;
V_ID V_NAME
---- --------------------------------------------------------------------------------
1 kk
3 iowkd
SQL> select * from child;
C_ID V_ID C_NAME
---- ---- --------------------------------------------------------------------------------
1    1 kll
2    1 ddkll
3    1 43kll
SQL> rollback;
Rollback complete
???????????????????????????????????????????????????????????????????С?
????SQL> update prim set v_id=4 where v_id=2;
????update prim set v_id=4 where v_id=2
????ORA-02292:Υ?????????????(A.FK_CHILD_PRIM) - ?????????
????SQL> update child set v_id=5 where v_id=2;
????update child set v_id=5 where v_id=2
????ORA-02291: Υ????????????? (A.FK_CHILD_PRIM) - δ???????????
????On delete cascade?????“???????”??????????????????????????????????“????”????????????????????????????£??????????????DBA??????????????????
????????????????????????????????On delete cascade???????????????????????????????????Щ???????????????????????磺??????д?????????????ù????????????????????????????????С??????????????????????????ù????????????????????????????on delete cascade??????????????????????“???”?????????????????????????£?????????“????”???????ж???????????????????????????????????????????????????????????????
???????On Delete Set Null
???????????????????Oracle????????????????????????????????????????????????????????????????????on delete set null???????????????????????????????????????????????????????????б?????
????SQL> alter table child drop constraint fk_child_prim;
????Table altered
????SQL> alter table child add constraint FK_CHILD_PRIM foreign key(v_id) references prim(v_id) on delete set null;
????Table altered
???????????????
SQL> delete prim where v_id=2;
1 row deleted
SQL> select * from prim;
V_ID V_NAME
---- --------------------------------------------------------------------------------
1 kk
3 iowkd
SQL> select * from child;
C_ID V_ID C_NAME
---- ---- --------------------------------------------------------------------------------
1    1 kll
2    1 ddkll
3    1 43kll
4      43kll
5      4ll
SQL> rollback;
Rollback complete
??????????????????????б??????????????????б仯??
????SQL> update prim set v_id=4 where v_id=2;
????update prim set v_id=4 where v_id=2
????ORA-02292:Υ?????????????(A.FK_CHILD_PRIM) - ?????????
????SQL> update child set v_id=5 where v_id=2;
????update child set v_id=5 where v_id=2
????ORA-02291: Υ????????????? (A.FK_CHILD_PRIM) - δ???????????