Mysql updating many fields
I want to update many fields randomly in a MySQL table, and I need to update two fields, one using unix timestamp and the other a date. For example, this is what I would have for the unix timestamp:
UPDATE `video` SET addtime= 1264982424 + (1355555555-1264982400)*RAND()
That should update the addtime randomly. However, there is another field in the table that is adddate and this uses mysql date. What can I do so that I write an addtime in Unix that is consistent with the adddate? I'm a bit of开发者_开发百科 a noob in MySQL.
Thanks!
EDITED:
If you need to keep adddate field synchronized with addtime field, you could insert a trigger like this:
CREATE TRIGGER upddate BEFORE UPDATE
FOR EACH ROW BEGIN
UPDATE video SET NEW.adddate=FROM_UNIXTIME(NEW.addtime);
END;
How about this one?
UPDATE video
SET addtime = 1264982424 + (1355555555-1264982400)*RAND(),
adddate = FROM_UNIXTIME(addtime)
精彩评论