【问题标题】:Update field in linked table in firebird更新火鸟链接表中的字段
【发布时间】:2012-07-23 13:43:50
【问题描述】:

我有两张桌子——卡片和日记。卡片的 id (code) 是 journal(card-code) 中的链接器 .一张卡可以有很多日记,我需要用触发器从日记更新这张卡片表中的一个字段(时间)-我已经写了当前触发器,但它有错误。请帮我找到它。

 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

【问题讨论】:

  • 编译器说有一个未知的token

标签: sql triggers firebird


【解决方案1】:

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

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

一些cmets:

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

    更新卡集 card.lastupdate = :currentTimeOfChanging where ...

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 2011-03-26
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多