Rules for creating triggers for custom tables

When we are adding SQL statements to create and drop triggers for custom tables, ensure that you follow the appropriate rules.


Trigger creation SQL file

In the Utility server Docker container, add SQL statements to create triggers in the utilities_root/schema/9.0.0.0/db2/wcs.stage.trigger.sql file.

Put the SQL statements for creating triggers for custom tables in this file.


Trigger dropping SQL file

In the Utility server Docker container, add SQL statements to drop triggers to file utilities_root/schema/9.0.0.0/db2/wcs.droptrigger.sql.

Put the SQL statements for dropping triggers for custom tables in these files.


Trigger naming convention

The trigger naming convention is a guideline to ensure that new triggers for custom tables have unique names.

(DB2) WebSphere Commerce names a trigger by incrementing that last number of the last trigger in the db2/wcs.stage.trigger.sql file. Do not use this naming convention for our new triggers as our custom trigger names could conflict with any new triggers introduced by WebSphere Commerce in fix packs or later releases.

(Oracle) Ensure that the name of your new triggers follow the pattern found in the oracle/wcs.stage.trigger.sql file:


Create trigger requirements

We must create three triggers for the custom database table:

Note: Staging triggers log the changes to database records in to the STAGLOG table. The specific record that is changed is indicated by the value of the primary key and unique index. These values are the only pieces of data that gets logged in to STAGLOG. For the staging utility to work, the values of the primary key and unique index must not be updated in an UPDATE operation. The other two operations, INSERT and DELETE, do not change the primary key or unique index value. Your triggers must insert records into the STAGLOG database table with the following information in the STAGLOG table columns:


Primary key value insertions

When you insert primary key values into staging tables, always insert the values into the lowest numerically named columns that match the data type. The data that is generated by the staging triggers is stored in the STAGLOG database table. This data is read by the stagingprop utility, which requires primary key values to be placed in the lower numerically named columns.


Database table naming conventions

When you insert database table and column names into staging tables, use lowercase names for the database table and column names.


Related tasks
Creating triggers for custom tables