Pages - Menu

Random values every row in SQL table

Ever wonder how to generate random integer value in every row of a table?
The below query will generate a random value between 0 to 0.9999.... but the value will be the same for every row.

Update table
set column = rand() 

NewId() is actually re-generated per row, so play around with it with checksum and mod will get you the desired random values.

The following will generate random values between 0 – 99 for every column, and the value would be different.



Update table
Set column = abs(checksum(NewId())) % 100

No comments:

Post a comment