【发布时间】:2011-01-05 20:30:15
【问题描述】:
sqlite 触发器是否支持条件 if/case/when 语句?
假设我有以下设置:
CREATE TABLE someTable (id INTEGER PRIMARY KEY, someValue INTEGER);
CREATE TRIGGER update_another_table AFTER INSERT ON someTable
BEGIN
IF(new.someValue==0)
DELETE FROM another_table WHERE (...some condition);
ELSE
IF NOT EXISTS(SELECT anotherValue FROM another_table WHERE anotherValue =new.someValue)
INSERT INTO another_table VALUES(new.someValue, ...);
ELSE
UPDATE another_table SET anotherValue = new.someValue;
END;
但是会出现语法错误Sqlite error near 'IF': syntax error"
【问题讨论】:
标签: sqlite triggers insert if-statement