为什么我的触发器无法在MySQL中运行?

时间:2010-01-14 03:52:41

标签: mysql triggers

mysql> desc test;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| a     | int(10) unsigned | NO   |     | NULL    |                |
| b     | int(10) unsigned | NO   |     | NULL    |                |
| c     | int(10) unsigned | NO   |     | NULL    |                |
| str   | varchar(9)       | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql>  CREATE TRIGGER Capitalize BEFORE INSERT ON test
    ->  SET NEW.str = UPPER(NEW.str)
    ->  ;
ERROR 1064 (42000): 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 'SET NEW.str = UPPER(NEW.str)' at line 2
mysql>

我正在回答这个问题: How to define a column that can automate capitalizing?

1 个答案:

答案 0 :(得分:0)

CREATE TRIGGER Capitalize BEFORE INSERT ON test
FOR EACH ROW
    SET NEW.str = UPPER(NEW.str);

注意错误消息中的建议:“check the manual对应于您的MySQL服务器版本,以便使用正确的语法。”