When implementing “Triggers” , is it required to check the criteria/condition for trigger WHENEVER a change is made? If it is so, can someone have a large number of triggers?
Or else, how is it done?
Advertisement
Answer
Triggers add overhead to the operation they are working on. As with any other stored code, triggers can be made very complex and time consuming. You generally want to avoid those.
Part of the issue with triggers is that they often old locks on tables/rows. This can slow down other components of a query.
The number of triggers depends on the database. Some limit to a single trigger per action per table.
In general, it is considered good practice to use other mechanisms if they can be used — for instance, NULL
constraints, DEFAULT
values, and CHECK
constraints.
I tend to avoid triggers because they are hard to maintain. But there are well-designed, highly performant systems that do use them.