Reputation: 61
I am working with a MySQL database that has a table of customers. One of the columns consist of phone_numbers
varchar(10)
. My question is how can I create a simple loop that goes through all the customers and inserts a random phone numbers?
Upvotes: 2
Views: 6080
Reputation: 337
Use an UPDATE
statement with the RAND
and LPAD
functions (docs: RAND, LPAD).
Example (generates numbers from 0000000000 to 9999999999): UPDATE table SET phone_numbers = LPAD(FLOOR(RAND() * 10000000000), 10, '0')
Upvotes: 6