如何在表中完成数据插入后触发触发器
我有一个表 A
,我正在其中插入数据。然后进行一些计算来更新相同的表A
。
我想触发一个触发器,它在数据插入完成后(插入和更新之后)调用Procedure A
。
我该怎么做?
有没有其他方法可以自动执行...或者我必须在表A
中完成数据插入后手动运行程序A
。
更简单地说,我想知道如何在插入几行和提交后触发触发器,即不是针对每一行。
I have a table A
into which I am inserting data. Then some calculation is being done updating the same table A
.
I want to fire a trigger, which calls a Procedure A
after the completion of data insertion ( after insert and update ).
How do I do this?
Is there any other way to do it automatically... Or do I have to run Procedure A
manualy after the completion of data insertion in table A
.
More simply, I would like to know how to fire a trigger after inserting a few rows and a commit, i.e. not for each row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以定义为每行或每条语句触发的触发器(FOR EACH ROW 选项)。
如果我理解正确的话,你想在一堆语句之后触发触发器吗?别以为你可以。即使可以,我也宁愿不做。它们分散了你的程序流程/逻辑,让以后更难理解你的软件是如何工作的。
问候
You can define your trigger to be fired for each row or for each statement (FOR EACH ROW option).
If I understood you right, you would like to fire the trigger after a bunch of statements? Don't think you can. Even if you can, I would rather not do it. They scatter your program flow / logic and make it harder to understand later how your software works.
Regards
如果我正确理解您的问题,您希望在完成由多个插入/更新语句组成的事务后触发触发器吗?如果是这种情况,我认为您应该考虑在插入/更新操作完成后立即在程序流中调用您的
Procedure A
。换句话说:只有在为每行或每条语句调用触发器时,触发器才有用。
If I understand your question correctly, you want the trigger to fire after you completed your transaction consisting of several insert/update statements? If that is the case, I think you should consider calling your
Procedure A
in your program flow right after the insert/update operations are done.In other words: A trigger would only be useful, if it should be called for each row or for each statement.
在表中添加一列:例如“FINAL_ACTION”。在您预期的最终行动之前,请保持此列不变。然后仅使用此子句触发您的触发器:
Add one column to your table: e.g "FINAL_ACTION". Leave this column untouched untill your anticipated final action. Then have your trigger get fired only with this clause: