Oracle有主外鍵數據修改

僅做記錄,有tableAtableB兩張表,tableA (noA)主鍵字段是tableB(noB)字段的外鍵

當修改tableA  noA的時候會違背約束

解決方案一: 

        可以將子表tableB noB字段改成任意一個存在於tableB表中的值,然後修改tableA 中noA 爲新值 然後再將tableB的noB修改成新值;

解決方案二:

 解除主外鍵約束,然後進行修改,最後啓用主外鍵約束  具體步驟如下:

--(1)解除約束
alter table tableB  disable constraint   FK_tableB_noB(約束名字);

--(2)操作
update tableA set noA = 'new Value' where noA = 'old Value';
update tableB set noB = 'new Value' where noB = 'old Value';

--(3)啓用約束
alter table tableB enable constraint FK_tableB_noB(約束名字);

         

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章