SQL触发器仅触发一次 [英] SQL Trigger firing only once

查看:240
本文介绍了SQL触发器仅触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个数据库同步应用程序,并且我试图对其进行构建,以使其适合每个分层树结构,并且可以由用户自定义.

无论如何,有没有一种优雅"的方法来确保仅当某个特定进程(使用它的主程序)插入行时才激活TRIGGER,否则,如果在同一张表上有触发器在每个位置,同步插入将激活TRIGGER,并形成循环.

我有什么选择?分别登录的用户会有所帮助吗?

在此先感谢您.

I''m writing a Database Synchronization application, and I''m trying to build it so it would fit every hierarchical-tree structure, and can be customized by the user.

Anyway, Is there any "elegant" way to make sure that a TRIGGER is activated only when a row is inserted by some specific process (the Main program that uses it.), because otherwise, if there''s a trigger on the same table in every place, Synchronized insertion will activate the TRIGGER, and cycles will be formed.

What are my options? Would distinct logging in users would help?

Thanks in advance.

推荐答案

SELECT APP_NAME(), SYSTEM_USER, CURRENT_USER



您可以使用上面三个字段中的一个(或多个).您必须在触发器中执行检查,以确保它仅对您选择的应用程序/用户触发



You could use one (or more) of the three fields above. You would have to perform the check in the trigger(s) to make sure it only fires for your selected app/user


触发器每个语句触发一次,并且可以一次返回多个值,使用它们时必须考虑到这一点.

我不建议在您的情况下使用它们,而您最好考虑另一种方法.
Triggers fire once per statement and can return multiple values at a time, you have to take this into consideration when using them.

I would not recommend them in your scenario, and you had better think of another way.


这篇关于SQL触发器仅触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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