add trigger to every table in my H2 database

此生再无相见时 提交于 2019-12-24 02:48:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!