我有一個表tableA,它有一個列myID。 myID是tableA中的主鍵和tableB的外鍵。如何更新主鍵如果它也是另一個表的外鍵?
當我試圖TableA中更新特定記錄的身份識別碼:
update tableA
set myID = 123456
where myID= 999999
我得到這個錯誤:
The UPDATE statement conflicted with the FOREIGN KEY constraint "tableA_FK00". The conflict occurred in database "mydatabase" , table "tableA" , column 'myID'.
我已經設置身份識別碼的更新規則爲「級聯」和強制執行外鍵約束到'不',但我仍然無法更新。我應該如何繼續?
你爲什麼需要更新你的PK?似乎這裏有些事情沒有做好。 – 2012-01-30 04:47:54
檢查此帖:http://stackoverflow.com/questions/799100/changing-a-record-in-a-table-sql-server-that-has-foreign-keys – NoChance 2012-01-30 04:56:07
在級聯更新規則的存在下,任何更改/主鍵的更新會反映到外鍵。在這種情況下,您不必禁用外鍵約束。 – 2012-01-30 05:45:55