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

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Advanced SQL Engine
Teradata Database
Release Number
September 2020
Content Type
Programming Reference
Publication ID
English (United States)
Last Update

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