MERGE SQL

One of the most common types of data maintenance applications written today involves the merging of data from a set of new transactions into an existing table. Logic used within these applications follows a set of logic similar to the following:

						For each record in the transaction table
						  Find the corresponding record in the base table
						  If the record does not exist in the base table
						    Insert this record into the base table (new record)
						    Or Issue an error message that the record does not exist
						  Else
						    Update the existing record with the information from the transaction
						  End if
						End For
					

Some applications also include logic that would delete records from the existing table that are not found in the transaction table.

Rather than write an ...

Get DB2® Version 8: The Official Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.