MySQL trigger writing

Source: Internet
Author: User
Tags mysql tutorial

How to Write a trigger in the mysql tutorial */

Trigger_name: name of the trigger. My commonly used naming rules are t_name_tablename _ (B | a) (I | u | d), t: trigger ID, name: English name, tablename: Table name, B (before): before the event is triggered, a (after): after the event is triggered, I (insert): identifies the insert event, u (update): identifies the update event, d (delete): identifies a delete event;
Trigger_time: trigger time (before or after)
Trigger_event: event name (insert, update, or delete)
Tbl_name: Table Name (must be a permanent table)
Trigger_stmt: Execute the statement (which can be a compound language name). Use the old and new aliases to reference columns in the table related to the trigger program.

Delimiter //
Create trigger insert_mysql_test before insert on test
For each row
Begin
Insert into tem set id = new id, name = new name;
/* Id after new. name is the field name of the test table */
End
//
/* Mysql trigger Writing Method */

Create a mysql trigger

Create trigger trigger_name trigger_time trigger_event on tbl_name
For each row
Begin
Trigger_stmt
End;

Delete the producer
Syntax:
Drop trigger [schema_name.] trigger_name;
Note: The above operations require the super permission.

Drop trigger if exists 'trig _ t_chatuserinfo_ad'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.