创建触发器时mysql出错

时间:2016-02-18 07:17:26

标签: mysql

我有两个表格详细信息并购买。

当我尝试在购买桌子上创建触发器时,这似乎是一个错误

"#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;

1 个答案:

答案 0 :(得分:0)

试试这个:

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