现在它在elseif
给我1064错误。这是我第一次在5.1中创建触发器。我不确定我之前使用的版本,但是我成功使用了那个版本。
DROP TRIGGER IF EXISTS greentrucks.iCustomer;
DELIMITER GO
CREATE TRIGGER greentrucks.iCustomer AFTER INSERT
ON customer
For each ROW BEGIN
DECLARE count int;
SET @count = FOUND_ROWS();
If @count = 0
THEN LEAVE
ELSEIF EXISTS ( SELECT *
FROM INSERTED i
WHERE EXISTS (
SELECT p.email
FROM greentrucks.customer p
WHERE i.email = p.email))
THEN BEGIN
RAISERROR('That Email is already in use!',16,1);
IF @@Trancount >0
ROlLBACK TRANSACTION;
END IF
END IF
END
GO
DELIMITER ;
答案 0 :(得分:0)
LEAVE
需要一个标签。请参阅LEAVE documentation和sample in the LOOP documentation。此外,您需要使用分号终止LEAVE
语句。
MySQL在触发器中似乎没有LEAVE
的任何官方示例。 This blog post将标签放在BEGIN
之前。基于此,尝试这样的事情:
DROP TRIGGER IF EXISTS greentrucks.iCustomer;
DELIMITER GO
CREATE TRIGGER greentrucks.iCustomer AFTER INSERT
ON customer
For each ROW
my_label: BEGIN
DECLARE count int;
SET @count = FOUND_ROWS();
If @count = 0
THEN LEAVE my_label;
... and the rest of your code