mysql 触发器 多个事件,我可以在mysql的一个Trigger声明中定义多个事件吗?

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

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值