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.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
vjt1596846980081.ditamap
dita:ditavalPath
vjt1596846980081.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);