在更新 MySQL 中的特定列后触发触发器
在 MySQL 中,我想在更新特定列后触发触发器.
In MySQL, I want to fire a trigger after the update of specific columns.
我知道如何在 Oracle 和 DB2 中做到这一点:
I know how to do it in Oracle and DB2:
CREATE TRIGGER myTrigger
AFTER UPDATE of myColumn1,myColumn2 ... ON myTable
FOR EACH ROW
BEGIN
....
END
如何用 MySQL 做到这一点?
How to do that with MySQL?
推荐答案
您不能在 SQL 中的特定列更新上触发.它应用于一行.
You can't trigger on a particular column update in SQL. It is applied on a row.
您可以使用 IF
语句将 columm 的条件放在触发器中,如下所示:
You can put your condition for columm in your trigger with an IF
statement, as below:
DELIMITER //
CREATE TRIGGER myTrigger AFTER UPDATE ON myTable
FOR EACH ROW
BEGIN
IF !(NEW.column1 <=> OLD.column1) THEN
--type your statements here
END IF;
END;//
DELIMITER ;
相关文章