????Oracle??????????????????
???????????? ???????[ 2014/12/1 11:18:17 ] ????????????? Oracle ????
????????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) - δ???????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11