触发器创建及Navicat中使用
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
触发器创建及Navicat中使⽤
mysql中的触发器(trigger)使⽤
Trigger:
⽰例:
mysql>CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
Query OK, 0 rows affected (0.03 sec)
mysql>CREATE TRIGGER ins_sum BEFORE INSERT ON account
->FOR EACH ROW SET@sum=@sum+ NEW.amount;
Query OK, 0 rows affected (0.06 sec)
解析:<原谅我这懒惰的搬运⼯>
The statement creates a trigger named ins_sum that is associated with the account table. It also includes clauses that specify the trigger action time, the triggering event, and what to do when the trigger activates:
The keyword BEFORE indicates the trigger action time. In this case, the trigger activates before each row inserted into the table. The other permitted keyword here is AFTER.
The keyword INSERT indicates the trigger event; that is, the type of operation that activates the trigger. In the example, operations cause trigger activation. You can also create triggers for and operations.
The statement foll owing FOR EACH ROW defines the trigger body; that is, the statement to execute each time the trigger activates, which occurs once for each row affected by the triggering event. In the example, the trigger body is a simple that accumulates into a user variable the values inserted into the amount column. The statement refers to the column as NEW.amount which means “the value of the amount column to be inserted into the new row.”
Navicat中使⽤
1.选中要添加触发器的表;
2.打开其设计表;
3.打开触发器,在指定栏中设置触发器;。