MySQL触发器:达到某个datetime时更新 [英] MySQL trigger: Update when reaching a certain datetime
问题描述
我想创建一个MySQL触发器,每次在其他表格中的一个日期时间行之间更新一个表时,日期时间将低于现在。
I want to create a MySQL trigger that updates a table everytime one of the datetime rows in a different table reaches a datetime lower than now.
我会完成这个吗这是可能的吗?
说明:
table_1 table_2
-------- ------------------- -------- -
id 1 id 1
datetime 2011-05-10 11:11:11 counter 1
所以,当时间通行证和 NOW()
成为 2011-05-10 11:11:12
,那么我想要计数器上升1。
So, when time passes and NOW()
becomes 2011-05-10 11:11:12
, then I want to have the counter upped by 1.
推荐答案
您应该可以使用触发器和事件调度程序:
- 在每个更新/插入时触发的表上创建一个触发器
- 此触发器创建在行的datetime发生的计划事件,并更新您的第二个表
You should be able to do it using a trigger and the event scheduler:
- create a trigger on the table that is fired on every update / insert
- this trigger creates a scheduled event that occurs at the datetime of the row and updates your second table
这篇关于MySQL触发器:达到某个datetime时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!