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.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
ncd1596241368722.ditamap
dita:ditavalPath
hoy1596145193032.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);