Data compare only specified tables

tmztmz Posts: 6
edited November 16, 2005 1:27PM in SQL Toolkit Previous Versions
Hy!

In .Net application I would like to compare two databases. But not all tables.
How do I specify to compare only tables that I want.

I assume I have to change this code:
Tables commonTables=Tables.CreateFromIntersection(db1.Tables, db2.Tables);

But how?

Thanks!

Tomaz

Comments

  • Hello,

    You can limit the tables that will be compared by choosing to add or omit them from the TableComparisonSettings collection. Here is an example from the code snippets that come with Toolkit:
    //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));
    }
    
    You will want to insert a conditional inside this loop to only include the tables that you want.
    ]//set up the table comparison setting
    
    TableComparisonSettings settings=new TableComparisonSettings();
    foreach (Table table in commonTables)
    {
    if (table.FullkyQualifiedName=="[dbo].[foo]" || table.FullyQualifiedName=="[dbo].[bar]")
    settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));
    }
    
  • Hy!

    Thanks. I was aware of the if.... condition. But I thought there is a better (more proper) way to do this.

    Thank you anyway.

    Tomaz
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello,

    This is the only way I'm aware of. I haven't run across any 'atomic' settings that would help.
  • Hi!

    But how is it possible to specify which tables to compare in command line utility?
    I supose the same core is used.

    Tomaz
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Sure, that work is done for you with the pre-built tools. You can use the /include and /exclude switches to filter the tables.
  • Hi!

    Yes. I know. That's what I'm saying.

    Tomaz
  • Right -- the command line utilities use the specified command-line /include and /exclude command filters to create a conditional statement in the same code loop as the first example.
  • Hi!

    Aha. Now I get it. Thank you.

    Tomaz
This discussion has been closed.