Mysql trigger operation: mysql trigger operation

Source: Internet
Author: User

Mysql trigger operation: mysql trigger operation
Trigger operation: 1. trigger creation: (1 ). create trigger trigger_name before | after trigger_event on table_name for each row trigger_stmt; trigger_event indicates the Operation Event (insert, update, delete); trigger_stmt indicates the execution statement example: create trigger tri_test after insert on t1 for each row insert into t1_log values (USER (), 'insert record into t1', now ()); // after each row of table t1 is inserted, a data entry is inserted in Table t1_log. The data is the content after values. USER () it refers to the current user (built-in function), now () current time. (2 ). create trigger trigger_name before | after trigger_event on table_name for each row BEGIN trigger_stmt end; example: delimiter $ create trigger tri_testafter insert on t1 for each rowBEGINinsert into t1_log values (USER (), 'after insert table t1', now ()); insert into t1_log values (USER (), 'after insert table t1', now (); END $ execute delimiter after execution; restore separator; delimiter refers to switch separator, because multiple statements are separated by semicolons, you need to switch the default delimiter and switch back after the statement is executed. 2. view the trigger: show triggers/G; Query use information_schema in the information_schema database; select * from TRIGGERS where trigger_name = 'tri _ test' \ G; 3. the trigger modification trigger cannot be modified. You can only delete the original trigger and re-create a new trigger. 4. trigger deletion: drop trigger trigger_name;

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.