在firebird中链接表中更新字段

时间:2012-07-23 13:43:50

标签: sql triggers firebird

我有两张桌子 - 卡片和日记。卡的id(代码)是日志中的链接器(卡代码) 。一张卡可以有很多日记本,我需要通过触发器更新此卡表中的字段(时间) - 我已经写了当前的触发器,但它有错误。请帮我找到它。

 AS
 DECLARE VARIABLE currentTimeOfChanging timestamp;
begin
 select current_timestamp from rdb$database into currentTimeOfChanging;

 update card
 set card.lastupdate = currentTimeOfChanging;//!error
 where card.code = journal.cardcode
end

1 个答案:

答案 0 :(得分:1)

我想你想要这样的触发器:

CREATE TRIGGER SetLastUpdateTS FOR journal
ACTIVE AFTER UPDATE
AS
BEGIN
  UPDATE card SET lastupdate = CURRENT_TIMESTAMP WHERE code = NEW.cardcode;
END

一些意见:

  • 您不需要currentTimeOfChanging临时变量,您可以直接在current_timestamp声明中使用UPDATE;
  • 你必须在变量前加上“:”,并且没有“;”在PSQL代码中的UPDATE语句中的变量之后。所以你的原始陈述应该是

    更新卡片组card.lastupdate =:currentTimeOfChanging where ...

  • 而不是journal.cardcode您使用NEW和/或OLD上下文变量来引用当前语句的值(触发触发器)。

    < / LI>
相关问题