gpt4 book ai didi

sql - 触发自动将元组添加到关系

转载 作者:行者123 更新时间:2023-12-03 19:12:21 25 4
gpt4 key购买 nike

我正在尝试在SQLITE上创建触发器,以在将某些内容添加到某个表时自动将元组添加到另一个表,但是首先,我想检查添加的内容是否属于另一个第三表。

这是我的触发器:

DROP TRIGGER IF EXISTS atualizaBibliotecas;

CREATE TRIGGER atualizaBibliotecas
AFTER INSERT ON FoiComprado
FOR EACH ROW
BEGIN
SELECT CASE
WHEN
(
SELECT count(*)
FROM Album
WHERE idItem = NEW.idItem
) <> 0
THEN INSERT INTO Possui(idItem, email, dataAquisicao) VALUES(11,'aaaa@bbbb.com', '2019-05-14');
END;


这是我收到的错误:

Error: near line 8: near "INSERT": syntax error


第8行:

CREATE TRIGGER atualizaBibliotecas

最佳答案

我相信你想要:-

CREATE TRIGGER atualizaBibliotecas
AFTER INSERT ON FoiComprado
FOR EACH ROW
WHEN
(
SELECT count(*)
FROM Album
WHERE idItem = NEW.idItem
) <> 0
BEGIN
INSERT INTO Possui(idItem, email, dataAquisicao) VALUES(11,'aaaa@bbbb.com', '2019-05-14');
END;

关于sql - 触发自动将元组添加到关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56309338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com