我正在尝试在 MYSQL 5.0.95 中创建一个触发器,以防止在电子邮件字段中找不到 @ 符号时发生插入。我知道除了触发器之外还有其他方法可以做到这一点,但我真的很想了解触发器是如何工作的
CREATE TRIGGER triggerUsersEmail
BEFORE INSERT ON Users
FOR EACH ROW
BEGIN
IF (Users.email NOT LIKE '%@%') THEN
DECLARE dummy INT;
SELECT not a valid email address INTO dummy FROM Users WHERE 1=1
END IF;
END;$$
我在 PHPMYADMIN 中使用 $$ 分隔符运行上述内容,但出现此错误:
#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 'DECLARE dummy INT; SELECT not a valid email address INTO dummy FROM Users WHERE' at line 6