By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,345 Members | 2,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,345 IT Pros & Developers. It's quick & easy.

Generating random unique numbers and insert them into a columun.

P: 1
Hey people,


I wanted to generate a random number (for a unique and unpredictable memberID) and insert it into every memberID column which has not a memberID already (equals NULL).
I dont want to change the already generated memberIDs in the meantime.

Expand|Select|Wrap|Line Numbers
  1. SELECT FLOOR(10000 + RAND() * 89999) AS random_number
  2. FROM customer
  3. WHERE "random_number" NOT IN (SELECT memberID FROM customer)
  4. LIMIT 1
This is the SQL query to generate a unique random number (I hope :D).
So how can I manage the rest now?

Or even better, can I generate a random, unique and unpredictable ID automatically for every new member I create?
Jul 5 '17 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
Maybe it's easier ti use the MySQL function UUID_SHORT() for this?

Another solution might be to create a trigger
Oct 28 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.