Under normal condition, I would set up three queries to check for it before doing the insertion of records. It will be untidy to code if this is done the normal way. Triggers then is the more cleaner way to do so.
The setting up is quite straight forward.
Create trigger
It then followed by the list of conditions
case when ((select....) >
when ((select
when ((select
end;
In the script we just need a normal insert SQL with a exception check, (PHP try and catch) to get the error message. Just get the different message and act accordingly. It is very much cleaner in coding without much coding in the application.
This trigger can be inserted externally using normal SQL procedure. It can also be removed the same way. Obviously, same name trigger must be removed first before insert.
There are much more type of triggers. This one only talks about INSERT BEFORE.
No comments:
Post a Comment