本文主要向大家介绍了MySQL数据库之MySQL 触发器实现 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。

Summary: in this tutorial, you will learn about MySQL triggers implementation. In addition, we will show you how MySQL stores trigger definitions and the limitations of triggers in MySQL.

Introduction to MySQL triggers

In MySQL, a trigger is a set of SQL statements that is invoked automatically when a change is made to the data on the associated table. A trigger can be defined to be invoked either before or after the data is changed by INSERT, UPDATE or DELETE statements. MySQL allows you to define maximum six triggers for each table.

BEFORE INSERT – activated before data is inserted into the table.

AFTER INSERT- activated after data is inserted into the table.

BEFORE UPDATE – activated before data in the table is updated.

AFTER UPDATE - activated after data in the table is updated.

BEFORE DELETE – activated before data is removed from the table.

AFTER DELETE – activated after data is removed from the table.

When you use a statement that makes change to the table but does not use INSERT, DELETE or UPDATE statement, the trigger is not invoked. For example, the TRUNCATE statement removes the whole data of a table but does not invoke the trigger associated with that table.

There are some statements that use the INSERT statement behind the scenes such as REPLACE statement and LOAD DATA statement. If you use these statements, the corresponding triggers associated with the tables if available will be invoked.

Triggers defined for a table must have a unique name. You can have the same trigger name that defines for different tables but it is not recommended. In practice, the names of triggers follow the following naming convention:

(BEFORE | AFTER)_tableName_(INSERT| UPDATE | DELETE)

MySQL Triggers Storage

MySQL stores triggers in a data directory e.g., /data/classicmodels/ with the files named tablename.TRG and triggername.TRN:

The tablename.TRG file maps the trigger to the corresponding table.

the triggername.TRN file contains the trigger definition.

You can back up the MySQL triggers by copying the trigger files to the backup folder. You can also backup the triggers using the mysqldump tool.

MySQL Trigger Limitations

MySQL triggers have all features in standard SQL however there are some limitations that you should know before using them in your applications.

MySQL triggers cannot:

Use SHOW, LOAD DATA, LOAD TABLE, BACKUP DATABASE, RESTORE, FLUSH and RETURN statements.

Use statements that commit or rollback implicitly or explicitly such as COMMIT, ROLLBACK, START TRANSACTION, LOCK/UNLOCK TABLES, ALTER, CREATE, DROP, RENAME, etc.

Use prepared statements such as PREPARE, EXECUTE, etc.

Use dynamic SQL statements.

Call a stored procedure or stored function.

In this tutorial, we have shown you how triggers are implemented in MySQL. We also discussed about trigger’s storage as well as trigger’s limitations in MySQL.

Related Tutorials

Introduction to SQL Trigger

Create Trigger in MySQL

Managing Trigger in MySQL

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

mysql数据库有触发器吗_MySQL数据库之MySQL 触发器实现相关推荐

  1. linux mysql 实战_Linux平台MySQL多实例项目实施_MySQL数据库基础与项目实战06

    Linux平台MySQL多实例项目实施_MySQL数据库基础与项目实战06 视频教程学习地址 Oracle/MySQL数据库学习专用QQ群:336282998.189070296 学完风哥本课程能熟悉 ...

  2. mysql建立修改表存储过程_MySQL数据库创建、表的创建、存储过程、触发器

    一.基本内容 (1) 使用SQL语句创建数据库: (2) 为数据库分配管理权限: (3) 定义表和数据库的完整性,student(学生表),course(课程表)和 sc(学生选课表), 并设置各个表 ...

  3. mysql部门人员排序设计_MySQL数据库访问性能优化

    MYSQL应该是最流行的WEB后端数据库.大量应用于PHP,Ruby,Python,Java 等Web语言开发项目中,无论NOSQL发展多么快,都不影响大部分架构师选择MYSQL作为数据存储. MYS ...

  4. mysql周德伟课后答案_mysql数据库搜索

    MySQL 数据库考试试题 及答案精编 Document number:WTT-LKK-GBB-08921-EIGG-22986 专业:移动通信 科目:MySQL 数据库 一.单项选择题 1.以下聚合 ...

  5. mysql药品库管理项目简介_MySQL数据库项目化教程简介,目录书摘

    内容简介: 本书以实际的学生竞赛项目管理系统为案例依托,从MySQL数据库的相关概念及理论知识出发,介绍系统需求分析.数据库设计与实施.数据库管理与优化等内容,最终实现学生竞赛项目管理系统的设计.开发 ...

  6. mysql计算机二级电子教程_MySQL数据库程序设计(2019年版全国计算机等级考试二级教程)...

    导语 内容提要 黄靖编写的<MySQL数据库程序设计(2019年版全国计算机等级考试二级教程)>根据教育部考试中心最新颁布的<全国计算机等级考试二级MySQL数据库程序设计考试大纲( ...

  7. mysql数据和性能平衡点_MySQL数据库性能优化(2)

    4.影响SQL性能的要素 MySQL数据库的性能不止受到性能参数和底层硬件条件的影响,在这两个条件一定的情况下,开发人员对SQL语句的优化能力更能影响MySQL数据库的性能.由于MySQL中不同数据库 ...

  8. mysql数据库设计课程大纲_MySql数据库教学大纲.doc

    范文 范例 指导 参考 word版 整理 XX学院计算机系 <MySql数据库>课程教学大纲 一.课程的性质与任务 (一)本课程的性质 <数据库(一)>主要面向计算机软件技术专 ...

  9. mysql数据库字段类型大全_mysql数据库字段类型详解

    MySQL支持大量的列类型,它可以被分为3类:数字类型.日期和时间类型以及字符串(字符)类型.本节首先给出可用类型的一个概述,并且总结每个列类型的存储需求,然后提供每个类中的类型性质的更详细的描述. ...

  10. mysql数据库缓存为多久_mysql数据库查询缓存总结

    概述 查询缓存(Query Cache,简称QC),存储SELECT语句及其产生的数据结果.闲来无事,做一下这块的总结,也做个备忘! 工作原理 查询缓存工作原理如下: 缓存SELECT操作的结果集和S ...

最新文章

  1. 【C++】多线程与条件变量【三】
  2. es查询java代码如何排序_elasticsearch 查询聚合结果排序
  3. 《统一沟通-微软-实战》-6-部署-2-中介服务器-1-定义中介服务器
  4. duilib基本布局学习(模仿百度网盘)及绑定按钮事件
  5. C语言用递归函数求1累加到100求和
  6. 两款cpu型号【E7400VSe8400】的对比。
  7. 【李宏毅2020 ML/DL】P82 Generative Adversarial Network | Improving Sequence Generation by GAN
  8. 通信原理matlab仿真教程 赵鸿图,通信原理MATLAB仿真教程中国通信学会普通高等教育“十二五”规划教材立项项目课件作者赵鸿图茅艳第8章节.ppt...
  9. 用Nginx禁止指定IP、国外IP访问我的网站
  10. 每次打开office2016相应应用都要配置进度的解决方法
  11. mysql日期查询索引_mysql – 如何为这种查询索引两个日期列
  12. Windows10系统 ADMUI3无法删除
  13. 主动防病毒产品及实测篇
  14. 教你发布Silverlight Bussiness Application(SQL Server 登录,局域网访问,以及使用ArcGIS Server服务需要注意的问题)...
  15. 让微积分穿梭于工作与学习之间(29):夹逼公式的几种变体
  16. NDK 开发之 ndk-build 的使用
  17. AMBA-ATB spec
  18. 智慧停车诱导技术方案
  19. Implement (interface)
  20. 探秘vue核心之虚拟DOM与diff算法

热门文章

  1. Java技巧:用一个循环语句输出九九乘法表!
  2. rocketmq订阅多个主题_RocketMQ 的消息模型
  3. linux ps mp,Linux中的命令ps(ps -aux)
  4. c++ cstring 转换 char_LeetCode 709. 转换成小写字母
  5. 基础知识:IDE集成开发环境(pycharm)、基本数据类型、用户的交互、运算符
  6. wxWidgets:wxUIActionSimulator 示例
  7. wxWidgets:调试 WxWindow 应用程序
  8. boost::sort模块实现spreadsort 键和数据排序示例
  9. boost::remove_copy_if相关的测试程序
  10. boost::array用法的测试程序