UPDATE t_users SET t_users.id=u.num1 FROM t_users INNER JOIN (SELECT row_number() over(order by id) AS num1,UserName FROM t_users) u ON u.UserName=t_users.UserName