17.00 - Example: OLD_NEW_TABLE AFTER UPDATE Trigger - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Release Date
September 2020
Content Type
Programming Reference
Publication ID
B035-1144-170K
Language
English (United States)

The following OLD_NEW_TABLE trigger definition is equivalent to the OLD_TABLE, NEW_TABLE trigger definition that follows it in terms of functionality; however, the OLD_NEW_TABLE syntax eliminates a join between OLD_TABLE and NEW_TABLE in the subquery, which makes it more high-performing.

     CREATE TRIGGER inventory_trigger 
       AFTER UPDATE ON inventory
       REFERENCING OLD_NEW_TABLE AS OldNewTab (OldValue, NewValue) 
         (INSERT INTO InventoryLogTbl   
            SELECT OldValue.ProductKey, OldValue.AvailQty,                    NewValue.AvailQty  
            FROM OldNewTab;);
      CREATE TRIGGER inventory_trigger AFTER UPDATE ON inventory
        REFERENCING OLD_TABLE AS OldTab 
                    NEW_TABLE AS NewTab
         (INSERT INTO InventoryLogTbl   
            SELECT OldTab.ProductKey, OldTab.AvailQty,                            NewTab.AvailQty  
            FROM OldTab, NewTab  
            WHERE OldTab.ProductKey = NewTab.ProductKey;);