我想自动将request_time
存储为更新关键字的当前时间。
这是一个示例表:
id request_time keyword
1 2011-02-03 8:00:08 free
在插入free
时,request_time
应设为NOW();
。
这是我的触发器,但它不起作用:
delimiter //
create trigger ai_update_userinput after update on user_input
for each row begin update user_input
set request_time = NOW(); end//
帮助表示赞赏。
答案 0 :(得分:1)
即使没有触发器,也应该使用timestamp列。请查看http://dev.mysql.com/doc/refman/5.0/en/timestamp.html,特别是表创建中列规范的'on update'子句的示例。
答案 1 :(得分:0)
时间戳列已设置DEFAULT CURRENT_TIMESTAMP
和ON UPDATE CURRENT_TIMESTAMP
时已提供此功能。请参阅the documentation。