I have tried using trigger for executing before each query but i want to do the same for select queries. Though triggers are not supported for select statement. Is there a way where a stored procedure is called before each INSERT, SELECT, DELETE and UPDATE queries in mysql.

  • The queries shouldn't be changed. Commented Jan 3 at 6:24
  • Welcome to the DBA.SE community. Please have a look at How to Ask. Your question doesn't contain enough details to be answerable. Please consider adding more details to your question by clicking on the edit link. e.g. what you have tried so far. Is this question about MySQL and Microsoft SQL Server? I'm asking because you added both tags. Thanks.
    – John K. N.
    Commented Jan 3 at 7:59
  • Let's see the stored proc; perhaps it is simple enough to be solved by something other than a Trigger.
    – Rick James
    Commented Jan 4 at 1:03

1 Answer 1


I can't find any alternative for trigger before SELECT query. But, there is a trick which is implemented by creating a function that performs the desired actions. Now, function evaluation is just a particular kind of expression. This means we can write a view that references our function, thus executing whatever statements we put in the function. Whenever the user select from the view, our function would be evaluated, and thus, the actions are performed.

Refer this link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.