现在它给我一个 1064 错误elseif
。这是我第一次在 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 ;