Hana Studio(SQL 脚本)触发器的条件更新

Conditional update on Hana Studio (SQL Script) trigger

我有两个例子 tables:

    TABLE1:
      ID    | COLUMN_B| COLUMN_C
   _________|_________|_________
       1    |    0    |    1
    ________|_________|_________
       2    |    0    |    1
    ________|_________|_________
       3    |    0    |    1


    TABLE2:
      ID    | COLUMN_E| COLUMN_F
    ________|_________|________
       1    |    Y    |    X
    ________|_________|_________
       2    |    Y    |    X
    ________|_________|_________
       3    |    Y    |    X

我想做的是使用 SQL 脚本在 Hana Studio 上编写一个触发器,当 table 1 的 B 列更新为时更新 table 2 的 E 列一个特定的值(比方说,100)。 来自 table 1 的行在 table 2 中引用第一列 (ID)。

我写了下面的代码:

create trigger "UPDATE_TABLES"
    after update of "COLUMN_B" on "TABLE1"
    referencing new row as new, old row as old
    for each row 
begin
    update "TABLE2"
    set "COLUMN_E" = 'my new value'
    where :old."COLUMN_B" = '100' and "TABLE1"."ID" = :old."ID";
end;

当我将第 1 行的 TABLE1.COLUMN_B 设置为 100 时,我希望代码将第 1 行的 TABLE2.COLUMN_E 更改为 "my new value",但没有任何反应。谁能指出我到底做错了什么?

菜鸟错误。我希望 column_e 值随着 column_b 值的变化而改变,但我实际上是在跟踪 column_b 的旧值。更正为:

create trigger "UPDATE_TABLES"
    after update of "COLUMN_B" on "TABLE1"
    referencing new row as new, old row as old
    for each row 
begin
    update "TABLE2"
    set "COLUMN_E" = 'my new value'
    where :new."COLUMN_B" = '100' and "TABLE1"."ID" = :old."ID";
end;

成功了!

我猜触发器代码中的 UPDATE 语句应该略有不同,如下所示

create trigger "UPDATE_TABLES"
    after update of "COLUMN_B" on "TABLE1"
    referencing new row as new, old row as old
    for each row 
begin
    update "TABLE2"
    set "COLUMN_E" = 'my new value'
    where :new."COLUMN_B" = '100' 
    and TABLE2.ID = :old."ID";
end;

否则,我在创建触发器时遇到语法错误 可以核实一下吗?