Example: Using MERGE to Update and Insert - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.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);