Excluding Columns before invoking CompareDatabases method

Disciple1991Disciple1991 Posts: 4
edited April 12, 2006 6:39AM in SQL Toolkit Previous Versions
Is there a way to exclude specific columns from being compared before invoking the CompareDatabases method?

I understand how to exclude Tables and I know that the GUI tool allows you to exclude columns from the DataCompare. I am assuming I can create a Table.Fields collection and just Add the columns I want to compare but have been unsuccessful in finding any help.

Thanks for any help.

//create an intersection of the tables
Tables commonTables=Tables.CreateFromIntersection(db1.Tables, db2.Tables);
//set up the table comparison setting
TableComparisonSettings settings=new TableComparisonSettings();
foreach (Table table in commonTables)
{
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));
}
session.CompareDatabases(db1, db2, settings);

Comments

  • I notice you are using the Toolkit API prior to version 5 - at least it seems that way from your question. The new version 5 data compare API has been re-engineered to make use of the SQL Compare engine for schema information and TableComparisonSettings has been completely done away with in favour of a much more flexible set of Mappings classes. You may want to have a look into it.

    Also to answer your question you will need to create your own intersection
    as you can't as you've noticed remove a field from the Fields collection.

    In your foreach loop I think you'll want something like the following...
    TableComparisonSetting setting = new TableComparisonSetting();
    setting.TableFullyQualifiedNameIn1 = table.FullyQualifiedName;
    setting.TableFullyQualifiedNameIn2 = table.FullyQualifiedName;
    setting.IncludeInComparison = include;
    setting.UniqueFieldDefinitions = table.PrimaryKey.Fields;
    foreach(Field field in table.Fields)
    {
      if (youWantTo)
      {
        setting.Fields.Add(field);
      }
    }
    

    If you look in your start menu in Red Gate there should be an entry for the help file 'The SQL Comparison and Synchronisation Toolkit' all the reference documentation is in there.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
Sign In or Register to comment.