Felix G Felix G - 6 months ago 10
SQL Question

Is it possible a trigger on a select statement with MySQL?

I know that triggers can be used on insert, update and delete, but what about a trigger (or sort of) on a select statement. I want to use a trigger to insert data on a table B when it is selected an existent record on a table A, it could be possible?.

Thanks in advance.

Answer

Not exactly a trigger, but you can:

CREATE FUNCTION myFunc(...) BEGIN INSERT INTO myTable VALUES(...) END;

And then

SELECT myFunc(...), ... FROM otherTable WHERE id = 1;

Not an elegant solution, though.