I have a large table in which, for testing purposes, I want to update a column to a different random value on each row.
If I say:
update MyTable
set MyCol = Rand()*100
then the value is, indeed, random – but it’s the same random number applied to every row.
I could use a cursor to iterate and update each row, one by one, and that’s obviously what I’ll fall back on if necessary. But is there some SQL syntax that will update each row with a different random value, in one succinct statement?
You need to seed
RANDwith something new for each row:RAND(CHECKSUM(NEWID()))