MySQL Flip-flop

Source: Internet
Author: User

Delete trigger drop TRIGGER   * from INFORMATION_SCHEMA. ' TRIGGERS ';
trigger syntax Trigger (TRIGGER): Monitors a situation and triggers an action. Trigger creation Syntax Four elements:1234. Trigger Event (insert/update/Delete) syntax: Create TRIGGER Triggernameafter/before insert/update/Delete on table name  for each row   # This sentence in MySQL is fixed generally is to do row-level trigger so write but not necessary for each row is the corresponding XXX event (insert update delete) in each row to understand that every time the table inserted (update delete) a row when the Beginsql statement triggered; End;
trigger When adding a user create  TRIGGER add_trigger_usafter INSERT on Us_usersfor each rowbegininsert to Us_person (' name ', age) VALUES (New . ' Name ',newage); End


Note: The newly inserted row is represented by new, and the value of each column in the row is represented by the new. Column name.
trigger when modifying user create TRIGGER update_trigger_usafter update on Us_person  for  Set age=newwhere ' name ' =new. ' Name '; END

UPDATE Us_person set age=9999 where ' name ' = ' Wang ';
Attention:

For update: The modified line, the data before the modification, the old to indicate the value of the row before the column name reference was modified;

The modified data, denoted by new, new. The column name references the value in the row after being modified.

Trigger on Delete Create    from  where ' name ' = Old. ' name '; end//DELETE from  us_users where id=129007; Note that there  is no new in delete, for delete: There was a row, then was deleted, want to refer to the deleted line, old to indicate, old. The column name can refer to the value of the row being deleted. 
First of all, the difference between after and before: After is the first to complete the data additions and deletions, and then trigger, trigger the statement later than the monitoring and deletion of the operation, can not affect the previous additions and deletions to change the action, that is, first insert the order record, and then update the quantity of the goods; before is the first trigger, then add The triggered statements are preceded by additions and deletions to the monitor, and we have the opportunity to judge and modify the actions that will occur;

For example: to manipulate the data before judging, the value of the data, to modify

Main Source: http://www.cnblogs.com/zzwlovegfj/archive/2012/07/05/2578574.html

MySQL Flip-flop

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.