当前表
ID | Name 1 Joe 2 Phil 5 Jan 88 Rob
所需的表
ID | Name 1 Joe 2 Phil 3 Jan 4 Rob
提前致谢
您也可以暂时删除IDENTITY并尝试以下操作:
;WITH TBL AS ( SELECT *,ROW_NUMBER(ORDER BY ID) AS RN FROM CURRENT_TABLE ) UPDATE TBL SET ID = RN
或者,如果您不关心记录的顺序,这个
DECLARE INT @id; SET @id = 0; UPDATE CURRENT_TABLE SET @id = ID = @id + 1;