我想使用 MYSQL 触发器监视一张表上的多个事件。当这些事件发生时,我可以在这个数据库上做一些事情。下面的代码可以完成这个任务:
DROP TRIGGER if exists trigger_sample1;;
CREATE TRIGGER trigger_sample1
after UPDATE on table_1 for each row
begin
/* do something */
end ;;
DROP TRIGGER if exists trigger_sample2;;
CREATE TRIGGER trigger_sample2
after INSERT on table_1 for each row
begin
/* do something */
end ;;
DROP TRIGGER if exists trigger_sample3;;
CREATE TRIGGER trigger_sample3
after DELETE on table_1 for each row
begin
/* do something */
end ;;
Run Code Online (Sandbox Code Playgroud)
但我希望将这些触发器合并为一个触发器。我尝试了一些代码,例如:
DROP TRIGGER if exists trigger_sample;;
CREATE TRIGGER trigger_sample
after UPDATE, INSERT, DELETE on table_1 for each row
begin
/* do something */
end ;;
Run Code Online (Sandbox Code Playgroud)
这是行不通的。我也尝试过:
DROP TRIGGER if exists trigger_sample;;
CREATE TRIGGER trigger_sample
after UPDATE on table_1
after INSERT on table_1
after DELETE on talble_1
for each row
begin
/* do something */
end ;;
Run Code Online (Sandbox Code Playgroud)
这都不起作用。有什么建议吗?