简体   繁体   中英

How to create Teradata trigger (after insert update)?

I am trying to eliminate null values without making the column "not null" to avoid errors. So, I wanted to create a trigger to update each inserted row if it contains null to replace it with 'N'. The following syntax results in

"Executed as Single statement. Failed [5423: HY000] This trigger contains an invalid REFERENCING clause. Elapsed time = 00:00:00.018 STATEMENT 1: REPLACE failed. "

The Syntax:

Replace  TRIGGER DB.C_UP_CLIENTS
AFTER INSERT ON DB.CLIENTS
REFERENCING OLD table as old_clients_table
 NEW table  as new_clients_table
 FOR EACH Statement
(update DB.CLIENTS set NEEDS_AUTHENTICATION = 'N' where NEEDS_AUTHENTICATION is null;);

As Fred said, we don't have the OLD table for an AFTER TRIGGER. I would do this as follows (in an BEFORE INSERT trigger):

REPLACE TRIGGER DB.C_UP_CLIENTS ENABLED 
BEFORE INSERT ON DB.CLIENTS
REFERENCING NEW AS NEW_VALUE
FOR EACH ROW
BEGIN ATOMIC(
    SET NEW_VALUE.NEEDS_AUTHENTICATION =coalesce(NEW_VALUE.NEEDS_AUTHENTICATION ,'N');
    )
END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM