Mysql -- trigger operation, Mysql -- trigger operation

Source: Internet
Author: User

Mysql -- trigger operation, Mysql -- trigger operation
1. Why should I use a trigger?

2. Create a trigger 2.1 create a trigger with an execution statement

Example: There are two table objects in the database company: The Department table (t_dept) and the diary table (t_diary). When you create a trigger to insert a record to the Department table, the current time will be inserted into the diary table before insertion.

Department table:

   

Diary table:

Create a trigger:

Insert record:

Result: an additional record is added to the diary table.

2.2 create a trigger containing multiple execution statements

Syntax:

    

Example:

When a trigger is created to insert records into a department table, two records are inserted into the diary table.

Code Analysis:

    

Insert a record:

Result: There are two more records in the diary table:

3. view TRIGGER 3.1 view TRIGGER through show trigger statement

Syntax:

Example:

3.2 view the trigger by viewing the system table trigger

In Mysql, there is a system table triggers in the information_schema of the system database that stores all the trigger information. Therefore, you can query records in this table to view the trigger. The table structure is as follows:

  

 

View method:

View All triggers:

View the specified trigger:

4. delete a TRIGGER 4.1 delete a TRIGGER using the drop trigger statement

Syntax:

Example :"

 

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.