Informix

Informix 觸發器在插入前刪除記錄

  • August 23, 2019

我正在嘗試創建一個觸發器,以便systables_growth在插入發生之前簡單地從表中刪除記錄,基於date_added列上使用的 where 子句用於超過一定天數(在本例中為 15 天)的記錄:

我正在使用以下內容:

CREATE TRIGGER systables_growth_clnup
INSERT ON systables_growth
DELETE FROM systables_growth
WHERE date_added < (CURRENT - 15 UNITS DAY)

執行上述操作時出現以下語法錯誤。

CREATE TRIGGER systables_growth_clnup
INSERT ON systables_growth
DELETE FROM systables_growth
#^
#  201: A syntax error has occurred.
#
WHERE date_added < (CURRENT - 15 UNITS DAY)

如果您遵循CREATE TRIGGER的語法圖,您會發現操作子句需要BEFORE,FOR EACH ROWAFTER作為操作語句之前的前綴,並且觸發的操作段顯示您需要圍繞觸發的操作的括號。因此:

CREATE TRIGGER systables_growth_clnup
   INSERT ON systables_growth
   BEFORE (DELETE FROM systables_growth
           WHERE date_added < (CURRENT - 15 UNITS DAY)
          );

引用自:https://dba.stackexchange.com/questions/246105