Jump to content

Merge (SQL)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Xaje (talk | contribs) at 23:04, 10 March 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A relational database management system uses SQL MERGE (aka. upsert) statements to INSERT new records or UPDATE existing records depending on whether or not a condition matches.

MERGE INTO table_name USING table_name ON (condition)
WHEN MATCHED THEN UPDATE SET column1 = value1 [, column2 = value2 ...]
WHEN NOT MATCHED THEN INSERT column1 [, column2 ...] VALUES (value1 [, value2 ...])