ASKER
update x
set ln_no = ln_no_new
from (
select ln_no_new=row_number() over (partition by tr_ty, tr_no order by ln_no),
ln_no, tr_ty, tr_no
from mytable) x
But changing a primary key is usually no good idea. Plus, the above might not work as constraint checking might prevent the renumbering, in which case we would have to do the numbering twice, like withupdate mytable set ln_no = ln_no + 1e9
update -- like above
Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.
TRUSTED BY
update mytable
set @i = LN_NO = @i + 1