方法一:spa
With [TempTable] As ( Select [FieldID], Row_Number() Over(Order By [FieldID]) RowNumber From [Target] ) Update [Target] Set [FieldID] = RowNumber
方法二:code
Update [TempTable] Set [Target] = RowNumber From( Select [FieldID], ROW_NUMBER() Over(Order By [FieldID]) RowNumber from [Target] ) [TempTable]
[Template]爲臨時表命名,自定義。blog
[Target]爲須要更新的表。get
[FieldID]爲須要更新的列,存在於[Target]。it
[RowNumber]爲須要用到的列,臨時存在於[Target]的查詢結果中。class