I need to create a table with a random generator ID for users including letters and numbers for example: FT128 instead of default auto-increment ID

Thank you for any help.


Get a suitably large random number (eg 6 digits of RAND()), then double check against your existing table to see if that number is already taken. If so, try again.

If you want letters and digits, that can be achieved using BASE64():

| MID(TO_BASE64(RAND()), 6,6) |
| jQyMTE                      |

(I picked the middle because the start and end have some repeated stuff.)

You will still need the test for dups, but it should rarely hit a dup until you have millions of "users".

Note further... If you want only upper case, use UPPER().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.