我有两个表库存明细和购买。

当我尝试在购买表上创建触发器时,似乎会出现以下错误:

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 "


听见是我的代码

create TRIGGER afterinsert after insert on purchase for each row
BEGIN
set @qnty=(select quantity from stock_detail where brand_name = new.brand);
if(@qnty>=1) then
update stock_detail set quantity=@qnty+new.quanty;
end if;
END;

最佳答案

尝试这个:

delimiter //
create TRIGGER afterinsert after insert on purchase for each row
BEGIN
set @qnty=(select quantity from stock_detail where brand_name = new.brand);
if(@qnty>=1) then
update stock_detail set quantity=@qnty+new.quanty;
end if;
END;//
delimiter ;


有关更多信息,请参考:http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html

07-26 09:30