MERGE Examples | SQL Statements | Teradata Vantage - Example: Using MERGE to Update and Insert - Advanced SQL Engine - Teradata Database

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

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);