gpt4 book ai didi

mysql - 触发器,同一事件和时间的多个语句

转载 作者:行者123 更新时间:2023-11-29 19:27:26 26 4
gpt4 key购买 nike

我想在插入时将同一个表“clients”的 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)

...应该在与第一个事件相同的事件和时间触发。

这可能吗?

最佳答案

我找到了解决方案。使用 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

关于mysql - 触发器,同一事件和时间的多个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com