Generate SQL scripts for triggers
I often have to create trigger which will copy all contents of the rows on insert/update to another table. As some tables have 200 columns this often is a long writing of
CREATE TRIGGER scheme.trigger AFTER UPDATE ON scheme.table
REFERENCING OLD as o_row NEW as n_row
FOR EACH ROW
BEGIN
INSERT INTO archive (...) VALUES(...);
END;
This is a lot of typing. Is there an easy generator to build these type of triggers, in开发者_开发百科serts, updates?
If the process has a set of input parameters and the process with these parameters is the same, you can call a stored procedure from the trigger, passing the parameters. In this way, you do not have to recopy/recreate all these DML sentences.
I don't know of a tool that generates the CREATE TRIGGER statements for you, but I've generated that DDL from a query many times, and the only view I ever needed to references was SYSCAT.COLUMNS
The following factors will simplify the trigger DDL generator query you'll be writing: - Column names between original table and archive table are identical. - None of the columns in the target table are defined as GENERATED ALWAYS, otherwise you'll need to omit them from your INSERT statement.
精彩评论