Triggers

A trigger is a database object that automatically sets off a specified set of SQL statements when a specified event occurs.

If the --firetrigger option is enabled on a replicate, any triggers defined on a table that participates in replication are invoked when transactions are processed on the target server. However, because Enterprise Replication only replicates the final result of a transaction, triggers execute only once on the target regardless of how many triggers execute on the source. In cases where the final evaluation of the transaction results in no replication (for example, an INSERT where the final row image is a DELETE, as shown in Table 1), no triggers execute on the target database.

If the same triggers are defined on both the source and target tables, any insert, update, or delete operation that the triggers generate are also sent to the target database server. For example, the target table might receive replicate data caused by a trigger that also executes locally. Depending on the conflict-resolution rule and scope, these operations can result in errors. To avoid this problem, define the replicate to not fire triggers on the target table.

You might want to design your triggers to take different actions depending on whether a transaction is being performed as part of Enterprise Replication. Use the 'cdrsession' option of the DBINFO() function to determine if the transaction is a replicated transaction. The DBINFO('cdrsession') function returns 1 if the thread performing the database operation is an Enterprise Replication apply or sync thread; otherwise, the function returns 0.

For more information on triggers, see Enabling Triggers and the CREATE TRIGGER section in IBM® Informix® Guide to SQL: Syntax.


Copyright© 2018 HCL Technologies Limited