You are here: Decision Strategy Manager > Interaction History > Sample scripts for archiving and purging > IH scripts for DB2 Database Software

IH scripts for DB2 Database Software

Use these scripts with DB2 Database Software to archive or purge the interaction history tables on Windows OS. The scripts allow you to move the FACT table records, merge the Dimension records, and delete the records from the FACT table. Before you use any of the scripts, back up the source and target interaction history tables and create indexes on the columns. Indexes improve performance when you read data from the archived tables.

Note: The IH scripts contain variables like <Filename_withpath> and <SOURCE_DATABASE> which you need to specify before executing any of the sample scripts below.

Moving the FACT table records

Before you perform this task, make sure you have full access to the source and the destination databases (you need the database admin privileges).

  1. Connect to the source database.
  2. EXPORT TO "<Filename_withpath>.IXF" OF IXF SELECT * FROM PR_DATA_IH_FACT

  3. Connect to the target database.
  4. Move data.

Merging the dimension records

Before you perform this task, make sure that all the dimension tables are created and have index on the PZID column.

  1. Connect to the target database.
  2. Merge the records from the temporary table to the actual dimension table.

    MERGE INTO PR_DATA_IH_DIM_<DIMENSION_NAME> T USING (SELECT column1 [, column2 ...] FROM <SOURCE_DATABASE>.<SOURCE_SCHEMA>.PR_DATA_IH_DIM_<DIMENSION_NAME>) S ON (T.PZID = S.PZID)WHEN NOT MATCHED THEN INSERT (column1 [, column2 ...]) VALUES (S.column1 [, S.column2 ...])

If you want to merge the dimension records from the source database to the target database, repeat this procedure for all the dimension tables.

Deleting the records from FACT table

  1. Connect to the source database.

  2. Execute the following script:

    DELETE FROM PR_DATA_IH_FACT WHERE PXOUTCOMETIME < TO_DATE(<DATE_STRING>, <DATE_FORMAT_STRING>);

Example:

DELETE FROM PR_DATA_IH_FACT WHERE PXOUTCOMETIME < TO_DATE('0015-01-07 00:00:00', 'yyyy-dd-mm hh24:mi:ss')

Related Topics Link IconRelated information