Red Gate forums :: View topic - Adding "IF NOT EXISTS" clauses on insert statements?
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

Adding "IF NOT EXISTS" clauses on insert statements?

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
tim-s



Joined: 01 Aug 2011
Posts: 1

PostPosted: Mon Aug 01, 2011 8:22 pm    Post subject: Adding "IF NOT EXISTS" clauses on insert statements? Reply with quote

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!
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1123
Location: My desk.

PostPosted: Wed Aug 03, 2011 4:01 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group