Select Page

I recently came across a problem where I had to update hundreds of client records with a random 4 digit PIN code. After some research, I wrote the following SQL which did the trick.

It will update all records on the table: table_name and set a random 4 digit PIN between 1,000 and 9,999 on the column `column_pin`.

UPDATE `table_name` SET `column_pin` = FLOOR( 1000 + ( RAND( ) *8999 ) ) ;

 

I hope this was helpful to you.