在SQL Server中将同一表中的一列中的值更新为另一列中的值
我试图根据下面的场景用新id更新我的1表 在每个步骤中,在SQL Server中将同一表中的一列中的值更新为另一列中的值,sql,sql-server,Sql,Sql Server,我试图根据下面的场景用新id更新我的1表 在每个步骤中,new_ID列都会得到更新,如果它以前被使用过,如步骤2、3、4所示。该表可以保存一小部分记录或数百万条记录。正在尝试确定使用sql server的最佳方法 我的方法是使用带有2条update语句的存储过程 update old_new set newid = @newValue where oldid = @OldValue update old_new set newid = @newValue where newid = @Old
new_ID
列都会得到更新,如果它以前被使用过,如步骤2、3、4所示。该表可以保存一小部分记录或数百万条记录。正在尝试确定使用sql server的最佳方法
我的方法是使用带有2条update语句的存储过程
update old_new set newid = @newValue where oldid = @OldValue
update old_new set newid = @newValue where newid = @OldValue
这看起来像是一场即将发生的性能噩梦。欢迎提供任何指导。如果您关心性能,您可以将两个更新合并为一个:
update old_new set newid = @newValue where oldId = @OldValue or newid = @OldValue
如果您担心性能,可以将两个更新合并为一个:
update old_new set newid = @newValue where oldId = @OldValue or newid = @OldValue
这会是什么“性能噩梦”?这会是什么“性能噩梦”?