MySQL--触发器和事件

触发器和事件一、触发器1、触发器的基本概念​ 触发器是和表相关的一种数据库对象,可以将他看作一种特殊的存储过程,不需要人为调动的存储过程。关键字:trigger基本作用:通过对表进行数据的插入、更新或删除等操作来触发,从而执行某些特定的操作。2、触发器的创建可以在MySql命令界面通过’? create trigger '命令查看创建触发器的格式。mysql> ? create triggerDescription:Syntax:CREATE[DEFINER = u
摘要由CSDN通过智能技术生成

触发器和事件

一、触发器

1、触发器的基本概念

​ 触发器是和表相关的一种数据库对象,可以将他看作一种特殊的存储过程,不需要人为调动的存储过程。

  1. 关键字:trigger
  2. 基本作用:通过对表进行数据的插入、更新或删除等操作来触发,从而执行某些特定的操作。

2、触发器的创建

可以在MySql命令界面通过’? create trigger '命令查看创建触发器的格式。

mysql> ? create trigger

Description:
Syntax:
CREATE
[DEFINER = user] – 用户名
TRIGGER trigger_name – 触发器名
trigger_time --触发时机

​ trigger_event – 触发条件
​ ON tbl_name --表名

​ FOR EACH ROW – 对每一行
​ trigger_body – 触发器所做的事情
---------------------------------------------------------------------------------------------
trigger_time: { BEFORE | AFTER }

trigger_event: { INSERT | UPDATE | DELETE }

trigger_order: { FOLLOWS | PRECEDES } other_trigger_name

This statement creates a new trigger. A trigger is a named database
object that is associated with a table, and that activates when a
particular event occurs for the table. The trigger becomes associated
with the table named tbl_name, which must refer to a permanent table.
You cannot associate a trigger with a TEMPORARY table or a view.

Trigger names exist in the schema namespace, meaning that all triggers
must have unique names within a schema. Triggers in different schemas
can have the same name.

创建触发器的基本格式:
create TRIGGER <trigger_na

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值