Triggers in oracle

帅比萌擦擦* 提交于 2019-12-23 17:30:10

问题


What are the condtions where triggers can enhance or hinder the performance? When to use and when not to use the triggers in the system?

How triggers can be used to impose complex constraints?


回答1:


Executing a trigger always has some overhead-- at a minimum, you are doing a context shift from the SQL engine to the PL/SQL engine for every row that causes the trigger to fire. While the absolute magnitude of the overhead of firing a trigger is relatively constant, the percentage overhead is highly variable depending on how you are doing DML. If you have an application that is adding or modifying rows in sets, which is the fastest way to operate on relational data, triggers have a much larger relative impact on performance because the cost of those context shifts plus the cost of whatever the trigger is actually doing, quickly dominates the cost of doing the triggering DML.

In theory, a trigger can be used to enforce complex constraints because a trigger can query other tables or call functions to do complex comparisons. In practice, however, it is extremely difficult if not impossible to code these triggers in a way that is actually correct in a multi-user environment so it is generally not a good idea to design a system that would need constraints that look at data across tables. That generally indicates a problem with the data model.




回答2:


That's a very open question (a homework assignment possibly?). The Oracle Concepts Guide section on triggers is a good place to start learning about them.




回答3:


Just a link to an interesting post of Tom Kyte about trigger vs declarative constraint.



来源:https://stackoverflow.com/questions/1743169/triggers-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!