Reputation: 33
I have a table in MySQL Database with 8 columns. I want to create a new column. This column will automatically insert a random 6 digit value. Each new entry will be created with a unique value (from 000000 to 999999).
Is this possible?
Upvotes: 2
Views: 193
Reputation: 5271
What i think shoud do the job is :
create a porcedure that will handle the random data insert and check
if the values exists.
to generate random number
SELECT FLOOR(10000 + RAND() * 999999) AS random_number;
create a trigger that will call this proc every time an insert will be done !
CREATE TRIGGER bla_bla AFTER INSERT ON your_table
FOR EACH ROW BEGIN
call proc();
END;//
Upvotes: 1