我尝试在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_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