我有一个表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