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

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-12-13
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
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);