Help SQL Replication

Manipulating data in an SQL Replication environment

You can transform or enhance your source data before it is replicated to the target tables.

For example, you might want to manipulate your data in any of the following ways:
Use the Apply program to manipulate data, either before or after it applies data to the target, in any of the following ways:

You can manipulate data either before or after it is captured. Manipulate your data at registration instead of at subscription if you want to manipulate the data once and replicate transformed data to many target tables. Manipulate your data during subscription instead of registration if you want to capture all of the source data and selectively apply transformed data to individual targets.

In some replication scenarios, you might want to manipulate the content of the source data that is stored in the CD table. A trigger, an expression through the subscription, or a source view can all be used to get the same job done. Each method has its pros and cons. A trigger might be too costly in terms of CPU cycles used. A view lets you set up the function once rather than in multiple subscriptions.

For example, if a particular value is missing in the source table, you might not want the Capture program to capture null values.

You can use triggers on your CD table to specify conditions for the Capture program to enhance the data when inserting data to the CD table. In this case, you can specify that the Capture program should insert a default value in the CD table when it encounters a null value in the source. You can use the following code to create a trigger that supplies an unambiguous default if data is missing from the source table update:
CREATE TRIGGER ENHANCECD
NO CASCADE BEFORE INSERT ON CD_TABLE
REFERENCING NEW AS CD
FOR EACH ROW MODE DB2SQL 
WHEN (CD.COL1 IS NULL)
SET CD.COL1 ='MISSING DATA'
END

Instead of the trigger, you can use the COALESCE scalar function of DB2® in a registered source view or in a subscription expression. In a registered view, the coalesce function returns the first non-null value.

Partial sample that uses a source view
CREATE VIEW SAMPLE.SRCVIEW  (columns) AS SELECT 
       ... COALESCE(A.COL1, 'MISSING DATA') ...
       FROM SAMPLE.TABLE A
Partial sample using an expression
COALESCE(CD.COL1, 'MISSING DATA') 


Send your feedback | Information roadmap | The Q+SQL Replication Forum

Update icon Last updated: 2013-10-25