For MS SQL you can use NEWID and CHECKSUM :
UPDATE Users SET Gender = (CASE WHEN ABS(CHECKSUM(NEWID()) % 2) = 1 THEN 'M' ELSE 'F' END)
NEWID () generates a random GUID
CHECKSUM () generates a hash of this GUID
ABS () to do this is either 1 or 0
ATTENTION! Although some people suggest using the RAND - function , do not use it for this particular case. The request is as follows:
UPDATE Users SET Gender = CASE WHEN (RAND() > 0.5) THEN 'M' ELSE 'F' END
.. will cause you to have all the values โโof either M or F.
You can potentially use a RAND function with some value, for example Id, but the distribution of values โโwill not be very good: for example, the first 30 -40% of all M, then 30-40% of all F, then M again.
source share