MySQL 5.5。创建触发器时出错
我尝试在mysql 5.5中创建触发器,以防止在非空字段中插入空字符串:MySQL 5.5。创建触发器时出错,mysql,triggers,Mysql,Triggers,我尝试在mysql 5.5中创建触发器,以防止在非空字段中插入空字符串: CREATE TRIGGER check_empty_fields BEFORE INSERT ON customer_address FOR EACH ROW BEGIN IF new.customer_name = '' THEN SET new.customer_name = NULL ; END IF; IF new.customer_add
CREATE TRIGGER check_empty_fields
BEFORE INSERT ON customer_address
FOR EACH ROW
BEGIN
IF new.customer_name = '' THEN SET new.customer_name = NULL ;
END IF;
IF new.customer_address = '' THEN SET new.customer_address = NULL ;
END IF;
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 5
这种情况最好在UI验证或业务层而不是持久层中处理。为什么要在数据保存后检查数据?
customer\u address
既是表又是字段名,对吗?是的。Custommer address既是表名又是字段名