Scripting - Datacomp
This runs the Data Compare function in unattended mode.
The syntax of the Datacomp script function is not given. This is a complicated function. It is suggested that you:
- use the Data Compare window to set up (and test) the compare as per your requirements
- click on the File > View Compare Options, or Save Compare Options. AQT will generate a Datacomp function that will do the load as per the options you have specified on this window. You can incorporate this function in your batch script, or run it from the Run SQL window.
Specifying Primary Key and Columns
When running the datacomp function in batch, there are some parameters that do not need to be specified:
- you do not need to specify the Primary Key (pk) parameter if the tables have primary keys defined for them. AQT will automatically determine the primary key for the tables.
- you do not need to specify the columns to be compared (cols) if you are wishing to compare all columns in the tables.
This makes it easier to run multiple compares in batch (next section)
Running Multiple Compares
If you wish to compare multiple tables (such as all tables in a schema), this can be done as follows:
- in the Database Explorer, display all the tables in the schema you wish to compare.
- click on Tools > Generate Text, and enter a line such as the following:
--aqt datacomp,tab1=$1.$2,dbs1=<dbs1>,tab2=$1.$2,dbs2=<dbs2>,genscript=1,append=y,rpt=y
In this, replace <dbs1> and <dbs2> with the databases you are comparing between.
- Click on Generate. This will generate a script to compare all tables in the schema between the two databases.
- Copy the script to your batch script or Run SQL window. Change the first line in the scripts from append=y to append=n
- A script generated in this way will only work if all your tables have a Primary key / Unique key. It also assumes you are comparing all columns in the tables. If neither of these apply, you will need to change the datacomp statement for that table to specify the key columns and/or compare columns.