0

我有一张表格,可以记录有多少员工被分配到特定的班次。每次将用户分配到班次时,触发器都会通过将have列增加一来更新表。(这是由于性能问题)

触发器在插入后触发。但我也需要它在用户被删除时触发。我真的不想使用两个基本相同的触发器。

无论如何要在不使用程序的情况下实现这一点?

4

2 回答 2

1

No, you can not achieve that is you don't want to use stored procedure and two triggers. In MySQL, trigger can be attached only to one trigger_time & trigger_event - since it is defined such way:

trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }

therefore, in any case you'll need to have two triggers, and, if you don't want to repeat some code in them, you have to use stored procedure. Since you don't want to use stored procedure, I believe there's no acceptable solution for your problem.

于 2013-08-23T08:01:06.497 回答
0

A trigger is associated with a table, and a particular event (insert, update, delete). You have two actions: AFTER INSERT and AFTER DELETE, so you need two triggers.

于 2013-08-23T07:59:43.550 回答