我想改进以下代码,因为如果我可以为此触发器避免它,我不关心所有这些select语句。我要求在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 ; ||
答案 0 :(得分: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
是否必须以冒号为前缀,该练习取决于读者。