0

I have two table stock detail and purchase.

When I'm trying to create a trigger on the table purchase it will seems an error that

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

Hear is my code

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;
4
  • I dont see any delimiter for the trigger. If you write the trigger on mysql CLI then you need to set the delimiter other than the default one which is ; so you need delimiter // at the top and finally END;// delimiter ; Commented Feb 18, 2016 at 7:22
  • are you setting the delimiter before creating the trigger? dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html Commented Feb 18, 2016 at 7:22
  • stackoverflow.com/a/23160180/767881 Commented Feb 18, 2016 at 7:23
  • can u correctly write my codeing Commented Feb 18, 2016 at 7:26

1 Answer 1

0

Try this:

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 ;

For more info refer: http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.