# 第四章 触发器

在本节中，您将学习如何使用MySQL触发器。根据定义，触发器或数据库触发器是自动执行以响应特定事件的存储程序，例如在表中发生的插入，更新或删除。

数据库触发器是保护MySQL数据库中数据完整性的强大工具。此外，自动执行某些数据库操作(如日志记录，审核等)也很有用。

**1.SQL触发器简介**

* SQL触发器是存储在数据库目录中的一组SQL语句。每当与表相关联的事件发生时，就会执行或触发SQL触发器，例如插入，更新或删除。

  参考阅读：<http://www.yiibai.com/mysql/sql-triggers.html>

**2.MySQL触发器实现**

* 本教程将向您介绍MySQL触发器的实现。此外，还将向您展示MySQL如何在MySQL中存储触发器定义和触发器的限制。

  参考阅读：<http://www.yiibai.com/mysql/trigger-implementation.html>

**3.在MySQL中创建触发器**

* 本教程将向您展示如何在MySQL中创建一个简单的触发器来审核表的更改。我们将详细说明`CREATE TRIGGER`语句的语法。

  参考阅读： <http://www.yiibai.com/mysql/create-the-first-trigger-in-mysql.html>

**4.为相同的触发事件和动作时间创建多个触发器**

* 本教程将向您展示如何为MySQL中的相同触发事件和动作时间创建多个触发器。

  参考阅读：<http://www.yiibai.com/mysql/create-multiple-triggers-for-the-same-trigger-event-and-action-time.html>

**5.管理MySQL中的触发器**

* 您将学习如何管理触发器，包括在MySQL数据库中显示，修改和删除触发器。

  参考阅读：<http://www.yiibai.com/mysql/managing-trigger-in-mysql.html>

**6.使用MySQL计划事件**

* MySQL事件是基于预定义的时间表运行的任务，因此有时它被称为预定事件。MySQL事件也被称为“时间触发”，因为它是由时间触发的，而不是像触发器这样的表更新作为触发条件。

  参考阅读：<http://www.yiibai.com/mysql/working-mysql-scheduled-event.html>

**7.修改MySQL事件**

* 本教程将介绍如何使用`ALTER EVENT`语句修改现有的MySQL事件。在本教程之后，您将了解如何修改事件计划，如何启用或禁用事件以及如何重命名事件。

  参考阅读：<http://www.yiibai.com/mysql/modifying-mysql-events.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang-book.gitbook.io/mysql/di-si-zhang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
