在 INSERT 或 UPDATE 上触发的 MySQL 触发器?

标签 mysql sql triggers

有没有办法创建在 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/

相关文章:

sql - 在内部使用 OUTPUT/INTO 而不是插入触发器会使 'inserted' 表无效

java - Hibernate双向多对多实现

mysql - 如何在MYSQL存储过程中获取当前系统时间

php - 从一个表中选择多个数据并使用PHP表单插入到另一个表中

sql - 如何聚合多列的值?

mysql - 对于mySQL触发器,需要将字段值设置为所选值

c# - MySQL zip 安装默认文件 my.ini 在安装过程中无法打开

sql - 带有字母范围的 PATINDEX 排除变音符号(重音字符)

sql - 为什么 null||null 返回空值但 concat(null,null) 在 postgres 中返回空字符串?

postgresql - 如何获得一列连续递增的数字,而不遗漏任何数字?