Update by random value on random rows in MySQL


tl;dr

UPDATE my_table
SET
    -- ↓ possible values are 1 ~ 190
    country_id = FLOOR(1+ rand()*190),
    -- ↓ you also can use RAND and CASE instead of ELT()
    favorite_fluit = ELT(FLOOR(1+ rand()*3), 'orange', 'apple', 'strawberry');
-- ↓  50%
WHERE RAND() < 0.5
;

ref:


evalphobia's profile picture

Written by evalphobia who loves cloud technology and IPA🍺.