有没有办法创建在 UPDATE 或 INSERT 时触发的 MySQL 触发器?
有点像
CREATE TRIGGER t_apps_affected BEFORE INSERT OR UPDATE ...
显然,上面的方法行不通。那么,有没有创建两个单独触发器的解决方法? 我需要这个来更新另一个表上的运行计数器。
最佳答案
遗憾的是,没有简写形式 - 您必须创建多个触发器 - 每个事件一个。
doc说:
trigger_event
indicates the kind of statement that activates the trigger. The trigger_event can be one of the following:INSERT: The trigger is activated whenever a new row is inserted into the table; for example, through INSERT, LOAD DATA, and REPLACE statements.
UPDATE: The trigger is activated whenever a row is modified; for example, through UPDATE statements.
DELETE: The trigger is activated whenever a row is deleted from the table; for example, through DELETE and REPLACE statements. However, DROP TABLE and TRUNCATE TABLE statements on the table do not activate this trigger, because they do not use DELETE. Dropping a partition does not activate DELETE triggers, either. See Section 12.1.27, “TRUNCATE TABLE Syntax”.
关于在 INSERT 或 UPDATE 上触发的 MySQL 触发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6855099/