Home  >  Article  >  Database  >  What is a trigger? How to create a trigger?

What is a trigger? How to create a trigger?

王林
王林forward
2020-06-15 17:29:544263browse

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 触发器语句;
  • 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!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete