数据库触发器 [英] Database triggers
问题描述
有关触发器的consesus?爱em?恨em?认为他们在某些情况下有目的吗?
认为有必要绕过触发器意味着你做错了?
触发器通常使用不正确,引入错误,因此应避免。从来没有设计一个触发器来完成跨越表中行的完整性约束检查(例如dept的平均工资不能超过X。
Tom Kyte ,甲骨文副总裁表示,他更喜欢数据库的一个功能,删除触发器,因为它们在错误中经常发挥作用,他知道这只是一个梦想,而且,触发器在这里停留,但如果他可以从Oracle中删除触发器,他将(以及WHEN OTHERS条款和自治交易)。
可以正确使用触发器吗?绝对的。
问题是 - 在这么多
中没有正确使用我很愿意给
提供任何感知的好处只是为了获得
摆脱由
造成的滥用(和错误) - Tom Kyte
In the past I've never been a fan of using triggers on database tables. To me they always represented some "magic" that was going to happen on the database side, far far away from the control of my application code. I also wanted to limit the amount of work the DB had to do, as it's generally a shared resource and I always assumed triggers could get to be expensive in high load scenarios.
That said, I have found a couple of instances where triggers have made sense to use (at least in my opinion they made sense). Recently though, I found myself in a situation where I sometimes might need to "bypass" the trigger. I felt really guilty about having to look for ways to do this, and I still think that a better database design would alleviate the need for this bypassing. Unfortunately this DB is used by mulitple applications, some of which are maintained by a very uncooperative development team who would scream about schema changes, so I was stuck.
What's the general consesus out there about triggers? Love em? Hate em? Think they serve a purpose in some scenarios? Do think that having a need to bypass a trigger means that you're "doing it wrong"?
Triggers are generally used incorrectly, introduce bugs and therefore should be avoided. Never design a trigger to do integrity constraint checking that crosses rows in a table (e.g "the average salary by dept cannot exceed X).
Tom Kyte, VP of Oracle has indicated that he would prefer to remove triggers as a feature of the Oracle database because of their frequent role in bugs. He knows it is just a dream, and triggers are here to stay, but if he could he would remove triggers from Oracle, he would (along with the WHEN OTHERS clause and autonomous transactions).
Can triggers be used correctly? Absolutely.
The problem is - they are not used correctly in so many cases that I'd be willing to give up any perceived benefit just to get rid of the abuses (and bugs) caused by them. - Tom Kyte
这篇关于数据库触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!