MySQL Forums
Forum List  »  Triggers

If Exists Trigger syntax
Posted by: James Anderson
Date: January 29, 2017 05:55AM

I am not sure what is wrong with the following syntax.

I have tried breaking the sql up and executing the select statement by itself, no problem.

Suggestions very welcome.

James


Error

SQL query: Documentation

CREATE TRIGGER decrement_licenses BEFORE INSERT ON licenses
FOR EACH
ROW BEGIN
IF EXISTS
(
SELECT *
FROM distributors
WHERE name = NEW.distributor
AND licenses >0
)
THEN
UPDATE distributors SET licenses = licenses +1 WHERE name = NEW.distributor;
ENDIF;
END;

MySQL said: Documentation

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

Options: ReplyQuote


Subject
Views
Written By
Posted
If Exists Trigger syntax
2180
January 29, 2017 05:55AM
785
January 29, 2017 07:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.