Page 1 of 1

Difference Between Insert and Update / Update and Insert

Posted: Tue Dec 16, 2008 2:57 pm
by DeepakCorning
In my target DRS I see two options - Insert or Update and Update or Insert. Whts the difference between these two? I thought they do the same thing till I see it in my database the rows are getting duplicate if I use Insert or Update.

The other option is very slow . Please suggest.

Posted: Tue Dec 16, 2008 3:10 pm
by chulett
The difference should be pretty apparent from thier names - it is the order the actions are taken. In either case, the first action must fail for the second to fire, so you typically choose which to use based on which of the operations you'll have the majority of.

Unique keys can be critical to how well it works. For example, the only reason for an insert to fail should be that there is already a record with that unique key in the table so the insert fails and the update is performed. When update comes first, that 'fails' when it can't find the record to update and when that happens it tries to insert it. Like any update, that check can be slow without indexes to support it as each turns into a full table scan.

Me, I never use them, preferring instead to explicitly classify inserts versus updates and dedicate links to each.

Posted: Tue Dec 16, 2008 3:28 pm
by DeepakCorning
chulett wrote: the first action must fail for the second to fire, so you typically choose whi ...

Got it... Thats wht I was missing.... First Action Fail.. I had not contraints/inique keys in my table. Will test it now...