Home > Database > Mysql Tutorial > What is a trigger? How to create a trigger?

What is a trigger? How to create a trigger?

王林
Release: 2020-06-15 17:29:54
forward
4367 people have browsed it

What is a trigger? How to create a trigger?

What is a trigger?

  • #Triggers are used to "automatically" perform some operations after/before certain operations. (For example, if new student information is inserted, the number of students should be modified in the class table).

  • After insert delete update sets the trigger, executing the insert delete update operation will automatically trigger the set content.

  • A table can have up to 6 triggers (3*2, three operations*two times (before|after)).

Create trigger

Syntax:

create trigger 触发器名 before|after 事件 on 表名 for each row 触发器语句;
Copy after login
  • The trigger name is recommended to be trigger_xxx, so that it is easy to distinguish, trigger names cannot be repeated.

  • before|after represents the trigger statement execution time. If it is before, the trigger statement is executed before the insert delete update operation; after is after.

  • The event is one of the insert delete update operations.

  • for each row is a trigger that will trigger the corresponding operation on behalf of any record.

  • The trigger statement is the statement to be executed when the trigger is fired.

Recommended tutorial: mysql tutorial

The above is the detailed content of What is a trigger? How to create a trigger?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template