set @rownum=0; update product SET pc_id = (select @rownum := @rownum +1 as nid) ORDER BY p_id asc
可是这种在mysql中可以,但在sql server中不行,大神你们的方法怎样?
12345678_0001
浏览 2153回答 1
1回答
Qyouu
自增序号使用row_number函数,sqlserver 2008支持merge的写法,如:merge t as targetusing (select p_id, row_number() over (order by p_id) as pc_id_seq from t ) as sourceon (target.p_id = source.p_id)when matched thenupdate set target.pc_id = source.pc_id_seq;