sql server更新一列为行号

:引用自http://blog.csdn.net/lenovouser/article/details/52281726

查询显示行号:

1 SELECT
2     row_number () OVER (ORDER BY orderby_id) AS rowNumber
3 FROM
4     table_name;

 

 

更新一列为行号:

 1 UPDATE table_name
 2 SET new_row = t1.rowid
 3 FROM
 4     (
 5             select table_pk,
 6         row_number () OVER (ORDER BY orderby_id) AS rowid
 7     FROM
 8         table_name
 9     )     
10 ) AS t1
11 WHERE
12     t1.table_pk = table_name.table_pk;
posted @ 2017-11-14 11:35  SuMMerppp  阅读(1256)  评论(0编辑  收藏  举报