我需要更新记录的主键,但它也是另外两个表中的外键。而且我需要更新的主键也反映在子表中。SQL Server更新主键也是两个表中的外键
这里是我的查询和错误:
begin tran
update question set questionparent = 10000, questionid= 10005 where questionid = 11000;
Error 9/4/2009 10:04:49 AM 0:00:00.000 SQL Server Database Error: The UPDATE statement conflicted with the REFERENCE constraint "FK_GoalRequirement_Question". The conflict occurred in database "numgmttest", table "dbo.GoalRequirement", column 'QuestionID'. 14 0
我不记得如何去这样做,所以这就是为什么我在这里。任何帮助?
另一种选择:避免有一个可更改的主键。改为使用IDENTITY作为主键。对需要唯一的列保持唯一的约束。这可能超出了你的控制范围,但它对我们来说很好。我们的用户可以根据自己的需要更改ID,但不会影响实际的主键。 – 2009-09-04 14:23:34