僅做記錄,有tableA 與tableB兩張表,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(約束名字);