我正在从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
  在第10行结束

最佳答案

使用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 ;

关于mysql - 从我的PhpMyadmin SQL选项卡运行以下查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56175357/

10-11 07:52