I have a table named 'project1everything' and a column in that table named 'views' and I need to updated that column to have a random set of numbers from 1 - 10, each row with a different number. I tried looking around but nothing is working. I am using I assume the newest version of MySQL.
1 Replies
There is a RAND() function in TSQL but this function will generate a random number between 1 and 0 (a floating-point number).....
The below script can generate a random number based on the range of yours
Declare @maxRandomValue int
, @minRandomValue int ;
set @maxRandomValue = 1000
set @minRandomValue = 0
Select Cast( ( (@maxRandomValue + 1) - @minRandomValue)
* Rand() + @minRandomValue As int) As 'randomNumber'
now coming to the update query of yours, the below one is untested but give it a try...
Declare @maxRandomValue int
, @minRandomValue int ;
set @maxRandomValue = 1000
set @minRandomValue = 0
update <table> set <your_column> = Cast( ( (@maxRandomValue + 1) - @minRandomValue)
* Rand() + @minRandomValue As int) As 'randomNumber'