SELECT ROW_NUMBER() OVER ( ORDER BY Location ) i,* INTO #A FROM [GMSToolManage].dbo.[Location]; DECLARE @count INT; SELECT @count=COUNT(1) FROM #A; DECLARE @i INT=1; WHILE(@i<=@count) BEGIN PRINT @i UPDATE [GMSToolManage].dbo.[Location] SET ID=@i, CreateTime=GETDATE() FROM [GMSToolManage].dbo.[Location] T1 JOIN #A ON #A.i=@i AND #A.Location=T1.Location AND #A.Bin=T1.Bin SET @i=@i+1; END if OBJECT_ID(‘tempdb..#A‘) is not null drop table #A;