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.JustSomeFool– JustSomeFool2024年01月03日 06:24:20 +00:00Commented Jan 3, 2024 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.– John K. N.2024年01月03日 07:59:01 +00:00Commented Jan 3, 2024 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– Rick James2024年01月04日 01:03:43 +00:00Commented Jan 4, 2024 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