База данных / IS_to_STUD / Soft / 2.1.0.17798-Final / Firebird-2.1.0.17798-0_Win32 / doc / sql.extensions / README.merge
.txt----------------- MERGE statement ----------------- Function: Read data from the source and INSERT or UPDATE in the target table depending on a condition. Author: Adriano dos Santos Fernandes Format: ::= MERGE INTO [ [AS] ] USING [ [AS] ] ON [ ] [ ] ::= WHEN MATCHED THEN UPDATE SET ::= WHEN NOT MATCHED THEN INSERT [ ] VALUES Syntax rules: 1. At least one of and should be specified and each one should not be specified more than one time. Scope: DSQL, PSQL Examples: 1. MERGE INTO customers c USING (SELECT * FROM customers_delta WHERE id > 10) cd ON (c.id = cd.id) WHEN MATCHED THEN UPDATE SET name = cd.name WHEN NOT MATCHED THEN INSERT (id, name) VALUES (cd.id, cd.name) Notes: A right join is made between INTO and USING tables using the condition. UPDATE is called when a record exist in the left table (INTO), otherwise INSERT is called. If no record is returned in the join, INSERT is not called.