首页 > 代码库 > sqlserver新加一自增长的列,并且更新为行号

sqlserver新加一自增长的列,并且更新为行号

--查询行号

select row_number()over(order by CHECKTIME )as RowNum,*from CHECKINOUT

 

--更新id列为行号

update CHECKINOUT set id=t.rowId from
(select CHECKTIME, ROW_NUMBER() over(Order by CHECKTIME) as rowId from CHECKINOUT ) as t
where t.CHECKTIME = CHECKINOUT.CHECKTIME

sqlserver新加一自增长的列,并且更新为行号