UPDATE CattleProds
SET SheepTherapy=(ROUND((RAND()* 10000),0))
WHERE SheepTherapy IS NULL
If I then do a SELECT I see that my random number is identical in every row. Any ideas how to generate unique random numbers?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Instead of
rand(), usenewid(), which is recalculated for each row in the result. The usual way is to use the modulo of the checksum. Note thatchecksum(newid())can produce -2,147,483,648 and cause integer overflow onabs(), so we need to use modulo on the checksum return value before converting it to absolute value.This generates a random number between 0 and 9999.