Adding "IF NOT EXISTS" clauses on insert statements?

Automate and integrate using the SQL comparison API

Adding "IF NOT EXISTS" clauses on insert statements?

Postby tim-s » Mon Aug 01, 2011 8:22 pm

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!
tim-s
 
Posts: 1
Joined: Mon Aug 01, 2011 5:02 pm

Postby james.billings » Wed Aug 03, 2011 4:01 pm

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.
james.billings
 
Posts: 1146
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.


Return to SQL Comparison SDK Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests