patternsqlModerate
Update existing rows with squence number/char or any unique data
Viewed 0 times
rowsuniquenumbersquenceupdatewithcharanyexistingdata
Problem
I added a new column in the Table X
This column "cn" has to be unique and mandatory, but old data don't have any value.
How to update the existing records with sequecely or random unique data?
Thank you.
This column "cn" has to be unique and mandatory, but old data don't have any value.
How to update the existing records with sequecely or random unique data?
Thank you.
Solution
If you are happy with a number starting from 1 you can use
row_number().update T
set cn = rn
from (
select cn,
row_number() over(order by (select 1)) as rn
from TableX
) TCode Snippets
update T
set cn = rn
from (
select cn,
row_number() over(order by (select 1)) as rn
from TableX
) TContext
StackExchange Database Administrators Q#18215, answer score: 14
Revisions (0)
No revisions yet.