尝试创建触发器时出现此错误 - #1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在DECLARE orderCount INT附近使用正确的语法; SET orderCount =(SELECT COUNT(Order_No)FROM`s order' at line 5
delimiter /
CREATE TRIGGER CountOrders
BEFORE INSERT ON order
DECLARE orderCount INT;
SET orderCount = (SELECT COUNT(Order_No) FROM `order` WHERE Outlet = 1 AND
complete ='FALSE');
BEGIN
IF orderCount > 3
THEN SIGNAL 'To many orders pending'
END;
/
delimiter ;
我们非常感谢任何建议。谢谢。
答案 0 :(得分:0)
触发器中有几个问题。这是一个修改。
declare
部分应该在begin
之后,并且order是保留字,因此需要包含反引号
delimiter //
CREATE TRIGGER CountOrders BEFORE INSERT ON `order`
for each row
begin
DECLARE orderCount INT;
SELECT COUNT(Order_No) into orderCount FROM `order`
WHERE Outlet = 1 AND complete ='FALSE' ;
IF orderCount > 3 then
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'To many orders pending';
end if;
end ;//
delimiter ;