Example: Using a SET Clause - Advanced SQL Engine - Teradata Database

SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
ft:locale
en-US
ft:lastEdition
2021-07-27
dita:mapPath
spp1591731285373.ditamap
dita:ditavalPath
spp1591731285373.ditaval
dita:id
B035-1144
lifecycle
previous
Product Category
Teradata Vantage™

This example uses a SET clause as a triggered action statement in a BEFORE row trigger.

This is the subject table definition. Assume that values are loaded into the amount column of the table from a source file employing a USING INSERT request.

     CREATE TABLE subject_table (        entry_date DATE,        amount     INTEGER); 

This is the trigger definition:

     CREATE TRIGGER set_trig        BEFORE INSERT ON subject_table        REFERENCING NEW AS curr_value        FOR EACH ROW        SET curr_value.entry_date = DATE;        -- Adds the current system date to the entry_date column

Because of the SET clause assignment, the following triggering statement:

     USING (amount INTEGER)      INSERT INTO subject_table VALUES (NULL,:amount); 

executes as if it were this statement:

     USING (thisdate DATE, amount INTEGER)      INSERT INTO subject_table VALUES (:thisdate, :amount);