MySQL触发器插入和删除合而为一? [英] Mysql Triggers Insert and Delete in one?

查看:203
本文介绍了MySQL触发器插入和删除合而为一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个插入和删除触发器,两者都会做同样的事情.
我可以在一个触发器中创建它吗?
还是我需要两个单独的?
我四处张望,似乎所有人都有一个要删除,另一个要插入.

I need to create an insert and delete trigger, both will do the same thing.
Can I create this in one trigger?
Or do I need two separate ones?
I've had a look around and all seem to have one for delete and another for insert.

推荐答案

MySql不允许在同一触发器上发生多个事件.

MySql does not allow for multiple events on the same trigger.

一种选择是将代码放入过程中,并使每个触发器调用相同的过程-根据需要将旧/新行的尽可能多的信息传递给proc.

One option is to put your code in a procedure, and have each trigger call the same procedure - pass as much info of the old/new row to the proc as required.

这篇关于MySQL触发器插入和删除合而为一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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