tags:

views:

150

answers:

1
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>

I'm following this answer: http://stackoverflow.com/questions/2056488/how-to-define-a-column-that-can-automate-capitalizing/2056504#2056504

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

Heed the advice in the error message: "check the manual that corresponds to your MySQL server version for the right syntax to use."

Bill Karwin