15.10 - Example: OLD_NEW_TABLE AFTER UPDATE Trigger - Teradata Database

Teradata Database SQL Data Definition Language Syntax and Examples

prodname
Teradata Database
vrm_release
15.10
created_date
December 2015
category
Programming Reference
featnum
B035-1144-151K

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