What are the challenges you face when working across database platforms? Take the survey
Options

Adding "IF NOT EXISTS" clauses on insert statements?

tim-stim-s Posts: 2
I tried searching on this but came up blank ... basically, I'm using SQL Comparer SDK to compare the data in a master database to an older version so we can use the generated scripts to update multiple client-side databases to a newer version.

In the generated scripts, we really need each "INSERT" statement to be wrapped in an "IF NOT EXISTS" clause to avoid overwriting any conflicting client data with our default data. Is there some option I can set somewhere to force this?

Thanks!

Comments

  • Options
    I don't believe there's a way to add in the command you suggest. In the UI, the results are presented as records only in the source, only in the target and "different". Is it "different" records you're wanting to exclude (i.e. where the PK of the record matches one in the source, but the actual data differs)?

    If so, you might want to investigate controlling which differences are selected - I've not tried this on some useful data as yet, but something along the lines of:

    foreach (TableDifference d in session.TableDifferences)
    {
    d.SqlSynchronization = SqlSynchronization.AddSql;
    }

    Should make it only generate SQL for records to be inserted, leaving those that already exist (SqlSynchronization.UpdateSql) alone.
    Systems Software Engineer

    Redgate Software

Sign In or Register to comment.