Sql server 在SQL Server 2012中更新表的主键值
有一个名为“User”的表,UserId是它的主键。我必须更新主键字段“UserId”的值 由于用户表中只有一条记录,且该记录行的userId为“3”,因此我必须用“1”更新该值 由于以下外键,我们无法更新该字段Sql server 在SQL Server 2012中更新表的主键值,sql-server,Sql Server,有一个名为“User”的表,UserId是它的主键。我必须更新主键字段“UserId”的值 由于用户表中只有一条记录,且该记录行的userId为“3”,因此我必须用“1”更新该值 由于以下外键,我们无法更新该字段 [FK_dbo.UserProfile_dbo.ApiKeys_ApiKeyId] [FK_dbo.UserProfile_dbo.Clients_ClientId] [FK_dbo.UserProfile_dbo.Languages_LanguageId] [FK_dbo.Us
[FK_dbo.UserProfile_dbo.ApiKeys_ApiKeyId]
[FK_dbo.UserProfile_dbo.Clients_ClientId]
[FK_dbo.UserProfile_dbo.Languages_LanguageId]
[FK_dbo.UserProfile_dbo.Countries_UserCountry])
FOREIGN KEY([ApiKeyId,ClientId,LanguageId,UserCountry])
是什么阻止你这么做的?也许是外键?您尝试了什么?是的,外键很少。我正在更新问题,请检查。我猜
ClientId
映射到UserId
?您应该删除外键约束,更新两个表中的值,然后重新创建外键约束。我尝试了“ALTER TABLE foo WITH NOCHECK constraint ALL”删除所有约束,但没有成功。正确的代码是:ALTER TABLE drop constraint