从我的PhpMyadmin SQL选项卡运行以下查询

时间:2019-05-16 19:24:52

标签: mysql sql triggers phpmyadmin

我正在从PhpMyadmin SQL选项卡中运行以下查询:

CREATE TRIGGER trg_bansach ON bill AFTER INSERT AS
BEGIN
    UPDATE addbook
    SET Quality = Quality - (
        SELECT QualitySale
        FROM inserted 
        WHERE book_id = addbook.book_id
    )
    FROM addbook
    JOIN inserted ON addbook.book_id = inserted.book_id
END

但是每次我收到此错误消息时:

  

#1064-您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以在'FROM addbook'附近使用正确的语法           在哪里addbook.book_id =已插入。book_id   END'在第10行

1 个答案:

答案 0 :(得分:0)

使用delimiter

DELIMITER //
CREATE TRIGGER trg_bansach ON bill AFTER INSERT AS
BEGIN
    UPDATE addbook
    SET Quality = Quality - (
        SELECT QualitySale
        FROM inserted 
        WHERE book_id = addbook.book_id
    )
    FROM addbook
    JOIN inserted ON addbook.book_id = inserted.book_id;
END
//
DELIMITER ;