Example: Using MERGE to Update and Insert - Teradata VantageCloud Lake

Lake - Working with SQL

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2025-11-21
dita:mapPath
jbe1714339405530.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
jbe1714339405530

This example uses dynamically supplied values for an employee table row to update the table if the data matches an existing employee or insert the new row into the table if the data does not match an existing employee. Column empno is the unique primary index for the employee table.

This example can also be coded as the following upsert form of the UPDATE statement. See UPDATE (Upsert Form).

     USING (empno  INTEGER,
            name   VARCHAR(50),
            salary INTEGER)
     UPDATE  employee
       SET salary=:salary
       WHERE empno=:empno
       ELSE INSERT INTO employee
         (empno, name, salary) VALUES ( :empno, :name, :salary);