【SQL】在原表中创建标识列ID和CreateTime,并赋值

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;

 

【SQL】在原表中创建标识列ID和CreateTime,并赋值

上一篇:使用SQL*PLUS,构建完美excel或html输出


下一篇:MySQL ---- 过滤数据 通配符 like (七)