我想制作同一张桌子的2个字段(名字和姓氏)"客户"插入时大写。
mysql> show triggers LIKE 'clients'\G;
*************************** 1. row ***************************
Trigger: ucase_insert
Event: INSERT
Table: tlc
Statement: SET NEW.firstname = upper(NEW.firstname)
Timing: BEFORE
Created: 2017-02-04 11:53:45.87
sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Definer: root@%
character_set_client: utf8mb4
collation_connection: utf8mb4_unicode_ci
Database Collation: utf8_general_ci
我使用phpmyadmin作为界面。似乎我无法添加额外的第二个语句,如...
Statement: SET NEW.lastname = upper(NEW.lastname)
...应该在与第一个事件和时间相同的事件和时间触发。
这可能吗?
答案 0 :(得分:0)
我找到了解决方案。使用BEGIN
/ END
,我可以包含多个语句。看起来很琐碎,但我花了很长时间才发现......
mysql> show triggers LIKE 'clients'\G;
*************************** 1. row ***************************
Trigger: ucase_insert
Event: INSERT
Table: tlc
Statement: BEGIN
SET NEW.firstname = upper(NEW.firstname);
SET NEW.lastname = upper(NEW.lastname);
END
Timing: BEFORE
Created: 2017-02-04 11:53:45.87
sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Definer: root@%
character_set_client: utf8mb4
collation_connection: utf8mb4_unicode_ci
Database Collation: utf8_general_ci