2

我想改进下面的代码,因为如果我可以为这个触发器避免它,我不在乎拥有所有这些选择语句。我需要在 INSERT 期间为几个字段放置默认值。该代码有效,我只是在寻找其他建议。谢谢!

SET TERM || ;
CREATE TRIGGER populate_defaults FOR units
ACTIVE
BEFORE INSERT
AS
BEGIN
      new.value1 = (select value1 from defaults);
      new.value2 = (select value2 from defaults);
      new.value3 = (select value3 from defaults);
      new.value4 = (select value4 from defaults);
      new.value5 = (select value5 from defaults);
      new.value6 = (select value6 from defaults);
      new.value7 = (select value7 from defaults);
      new.value8 = (select value8 from defaults);
      new.value9 = (select value9 from defaults);
END ||
SET TERM ; ||
4

1 回答 1

2

您可以进行单选;试试这个:

SET TERM || ;
CREATE TRIGGER populate_defaults FOR units
ACTIVE
BEFORE INSERT
AS
BEGIN
  select   value1, value2, value3, value4
         , value5, value6, value7, value8
         , value9
    from defaults
    into   new.value1, new.value2, new.value3, new.value4
         , new.value5, new.value6, new.value7, new.value8
         , new.value9
END ||
SET TERM ; ||

我只是不记得是否new必须以冒号为前缀,该练习取决于读者。

于 2013-02-07T17:21:05.750 回答