我可以在mysql的一个Trigger声明中定义多个事件吗? [英] Can I define multiple events in one Trigger declaration in mysql?

查看:361
本文介绍了我可以在mysql的一个Trigger声明中定义多个事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的要求,
我有一个mysql表,对它的任何更改(插入/删除/更新)都应以完全相同的方式进行处理。根据mysql文档,创建触发器语法如下:

Here is my requirement, I have a mysql table on which any change (insert/delete/update) should be handled in exactly same way. According to mysql documentation create trigger syntax is as follows:

    CREATE
     [DEFINER = { user | CURRENT_USER }]
     TRIGGER trigger_name
     trigger_time **trigger_event**
     ON tbl_name FOR EACH ROW
     trigger_body

当我尝试放置多个事件时,其引发语法错误。
一种解决方案是我可以编写一个过程和3个触发器(每个事件一个),并从所有触发器中调用相同的过程。

When I'm trying to put more than one event, its throwing syntax error. One solution is I can write one procedure and 3 triggers (one for each event) and call the same procedure from all the triggers.

有什么复杂的方法吗?

Is there any sophisticated solution for this ??

推荐答案

否。仅支持一个事件。触发器必须是之前之后插入插入,更新删除

No. Only one "event" is supported. The trigger has to be either BEFORE or AFTER one of INSERT, UPDATE, DELETE.

如果许多共享的逻辑,您可以编写一个过程,然后从触发器的主体中调用该过程。

If you have lots of logic that is "shared", you could write a procedure, and call the procedure from the body of the trigger.

对此的复杂解决方案是使用不同的DBMS。否则,您必须在MySQL支持的范围内工作。

The sophisticated solution to this is to use a different DBMS. Otherwise, you have to work within the confines of what MySQL supports.

这篇关于我可以在mysql的一个Trigger声明中定义多个事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆