STK 3 - Specifying a different Comparison Key to DataCompare
Brian Donahue
Posts: 6,590 Bronze 1
- Date: 24 Sep 2004
- Versions affected: 3.x
When performing a data comparison programatically using SQL Toolkit's SQLDataCompare.Engine, you can select the unique index that Data Compare will use to match individual rows of data. In the Toolkit examples that ship with Red Gate SQL Bundle, the primary key column is used:
If you know the name of a unique index on the table that you'd rather use, you can specify it in place of table.PrimaryKey.Fields. Say you have a table named foo and a unique index called bar, you could change the code to look like this:foreach (Table table in commonTables)
{
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));
}
foreach (Table table in commonTables)
{
if (table.FullyQualifiedName=="foo")
{
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.Indexes["bar"].Fields));
}
else settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));
}
This would cause all tables to be compared using the primary key, except for the foo table will use the unique index called bar.