问题
im trying to add a trigger to every database table in my h2 database but im not sure how to do it.
I can select all the tables in the database but how do i loop through them to apply a trigger to each of them like below?
SELECT * FROM INFORMATION_SCHEMA.TABLES
and loop through each one and apply a trigger to each
CREATE TRIGGER MYTRIGGER AFTER INSERT ON TableName FOR EACH ROW CALL\"test.h2Trigger\"
回答1:
You can try create a stored procedure,in which you open a cursor to get each table name, and use server side prepared statement to create the trigger on each table. See http://forums.mysql.com/read.php?60,27979,30437 for how to use prepared statement.
It can be easier if you use a Perl or php script to do it.
Why do you need create trigger on every table?
来源:https://stackoverflow.com/questions/30287369/add-trigger-to-every-table-in-my-h2-database