DB Trigger - A Friend Or A Foe?
Database triggers are useful, and I am not going to bush it completely. In some cases, like the one I run into, triggers are more of a distraction and source of issues, rather than help and ease of headache-free maintenance. In order to understand the case, players must be introduced first.
- An application that collects information from user inputs to be stored in database at a very specific table that is uniquely assigned for the purpose of persisting user selections.
- An external service that is asked from time to time to perform a job based on the inputs user has provided from the application.
- Results of the job are stored in database, and for optimization purposes, some metadata stored as well, in a table of its own. What kind of metadata? Well, lets keep it simple and say that a certain job was executed or not. So the next time job (pretend that it’s scheduled) has to be run, it will first validate that it wasn’t executed before.
Some business process rules around the user inputs are defined as well