How can I make it so when an entry is created in a table, one of the columns unique_id
automatically gets filled with a randomly generated integer? Can this be done straight from mysql? I've seen that you can automatically fill it with a timestamp and such, so is it possible to automatically fill it with a randomly generated integer?
you can try this
SELECT FLOOR(10000 + RAND() * 89999) AS my_random_number
FROM mytable
WHERE "my_random_number" NOT IN (SELECT id FROM mytable)
LIMIT 1
OR SImply this SELECT FLOOR(RAND() * 1000000);
use RAND() and concat date and time with it so you can have a unique number..
Use UUID function,A UUID is designed as a number that is globally unique in space and time. http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_uuid
IF you need a unique number for id purpose. you may make your column auto-incremented. Remember this that if you are going with this you need to make it either unique or primary key. I think this is the easiest way. You will get a contiguous increment.