I am interested in writing a trigger that would ignore queries from a specific SQL user but take action on all others. Is there any way to do this?
A note, though: the user will need to do some queries, so I will need to allow some queries/deletes/etc.
If you have a trigger right now that you don’t want to fire (we have done this on audit triggers when moving large amounts of data), you can do something like at the start of the trigger:
If you wanted to do something differnt for just that person you would do something like:
Note several things about this. Use this code with much caution. First if you can do what you need through security rights, it is a much better choice. Hardcoding someone’s name into a trigger can cause strange results at some later time when all have forgotten that you put it in there. If you need to do in the short term (to move 100,000,000 million records in batches over a time into a database without hitting the auidit triggers for example), then don’t forget to change it back when the project is done. You don’t want to not audit someone’s actions forever especially if you are auditing financial transactions. Further, doing something in a trigger will only work for insert/update/delete. You cannot prevent selects from a trigger.