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?
Asked
Active
Viewed 5,158 times
2

AAEM
- 1,837
- 2
- 18
- 26

Quinton Thompson
- 61
- 1
- 10
-
Possible duplicate of [How do I populate a MySQL table with many random numbers?](https://stackoverflow.com/questions/11042546/how-do-i-populate-a-mysql-table-with-many-random-numbers) – Adan Sandoval Nov 21 '17 at 23:24
1 Answers
5
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')

RetroCraft
- 327
- 1
- 2
- 13