Reputation: 81292
I'm looking for a utility application that can wrap any insert statement in an IF NOT EXISTS statement.
I could write this program fairly easily, but wondering if there is some premade tool already for this?
Ideally would be nice to select the text of an insert statement in management studio, right click -> If not exists. After this the insert statement would be wrapped in an IF NOT Exists clause.
Upvotes: 3
Views: 137
Reputation: 36146
I dont think it exists, because even a "if not exist" clause can be relative. What is your parameter to tell a record doesnt exist? Only by primary keys? Or would the tool have to verify every single column on the table? Most of the tables have a InsertedDate and UpdatedDate on them, so if you choose option number 2, a record will never be considered duplicate, right? Also if you have numeric columns, you may also have a precision issue.
Upvotes: 1