0

I understand how to fill a field with random values, but I need my field to automatically update with a random value for each new column. For some reason, I'm having trouble figuring out how to do this.

By the way, as it says above, this is for a database in MySQL.

Thanks everyone

  • http://stackoverflow.com/questions/844527/how-to-populate-a-database-column-with-random-numbers – MikeB Sep 28 '12 at 17:08

1 Answers1

0

You can use a trigger to update a specific colum after insert like this:

DELIMITER |

CREATE TRIGGER randtrigger AFTER INSERT ON your_table
  FOR EACH ROW BEGIN
    UPDATE your_table SET some_column = rand()
    WHERE id = NEW.id;
  END;
|

DELIMITER ;
juergen d
  • 201,996
  • 37
  • 293
  • 362