Updating two tables in oracle
What I want to do is either insert only the new rows, or insert the new rows and update the changed rows (depending on the scenario). If I want to insert only the rows that will not violate the unique index, I can: Which method to use largely depends on requirements.
If the software must support multiple database backends or versions, perhaps the generic, standard queries are the best bet.
I have to start with one spreadsheet, then insert and/or update the differences from the others.Any data that violates any unique index will cause the same problem. For example, I might export some data to a spreadsheet, send it to a client, and the client might update or add some data and return the spreadsheet to me.That’s a terrible way to update data, but for various reasons, I’m sure many readers have found themselves in a similar situation.As in life, the most important thing is to find a good balance and determine which criteria really matter.
If this article was useful to you, you should subscribe to stay current with my upcoming articles. Edit 2006-02-26 I forgot to cross-reference INSERT IF NOT EXISTS queries in My SQL, a related post where I explain some variations on a particular scenario – for example, where there is no unique index on the column you want to avoid duplicating, or you want to allow only I'm Baron Schwartz, the founder and CEO of Vivid Cortex.
A suggestion: rather than check for existence insert/update, it’s usually more efficient to do it one of these ways: 1.