嘿,我在数据库中创建触发器时遇到了一点问题。
我有一个名为“位于”的表,其中包含:
- 国家
- 城市
- 省
- 湖
- 海
- 河
所以 Lake、Sea 和 River 是外键。
我创建了这三个约束:
ALTER TABLE located
ADD CONSTRAINT locatedLake
FOREIGN KEY (lake)
REFERENCES Lake(name)
ON DELETE SET NULL;
ALTER TABLE located
ADD CONSTRAINT locatedRiver
FOREIGN KEY (river)
REFERENCES River(name)
ON DELETE SET NULL;
ALTER TABLE located
ADD CONSTRAINT locatedSea
FOREIGN KEY (sea)
REFERENCES Sea(name)
ON DELETE SET NULL;
所以每次我删除一个湖泊、河流或海洋时,它都会被设置为 NULL。
现在我尝试创建这个触发器:
CREATE OR REPLACE TRIGGER deleteFromLocated
AFTER UPDATE ON located
FOR EACH ROW
BEGIN
DROP FROM located WHERE sea IS NULL AND river IS NULL AND lake IS NULL;
END;
/
但后来我得到一个变异错误。
目标是删除这三件事为空的每个元组。
也许有人可以帮助我?
提前致谢