2010-01-14 7 views
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> 

que je suis cette réponse: How to define a column that can automate capitalizing?Pourquoi mon déclencheur ne fonctionne pas dans MySQL?

Répondre

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

Tenez compte des conseils dans le message d'erreur: « check the manual qui correspond à votre version du serveur MySQL pour la bonne syntaxe à utiliser. »

Questions connexes