16.20 - Example: Using a SET Clause - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL Data Definition Language Syntax and Examples

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-24
dita:mapPath
wkf1512081455740.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval

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