I have a table in which I added a column called phone - the table also has an identifier specified as a primary key that automatically indicates. How to insert a random value into a column of a phone that will not be duplicated. The following UPDATE statement inserted random values, but not all of them were unique. In addition, I am not for sale, I also applied the phone field correctly, but I encountered problems when trying to install it as an int (11) w / ALTER TABLE command (basically, it worked correctly, but when adding a line with a new phone number, inserted value was transferred to another number).
UPDATE Ballot SET phone = FLOOR (50000000 * RAND ()) + 1;
Spec table
+ ------------ + -------------- + ------ + ----- + -------- - + ---------------- +
| Field | Type | Null | Key | Default | Extra |
+ ------------ + -------------- + ------ + ----- + -------- - + ---------------- +
| id | int (11) | NO | PRI | NULL | auto_increment |
| phone | varchar (11) | NO | | NULL | |
| age | tinyint (3) | NO | | NULL | |
| test | tinyint (4) | NO | | 0 | |
| note | varchar (100) | YES | | NULL | |
+ ------------ + -------------- + ------ + ----- + -------- - + ---------------- +
source share