Mysql things (11) trigger 2

Source: Internet
Author: User


Mysql things (11) trigger 2 link: Mysql things (1) mysql Installation http://www.bkjia.com/database/201210/162314.html Mysql (2) Database Operations http://www.bkjia.com/database/201210/162315.html Mysql (3) operations on Data Tables http://www.bkjia.com/database/201210/162316.html Mysql (4) Data Table query operations http://www.bkjia.com/database/201210/162317.html Mysql (5) operation time http://www.bkjia.com/database/201210/162318.html;Mysql Those things (6) String Pattern Matching http://www.bkjia.com/database/201210/163969.html;Mysql Those things (7) In-depth select query http://www.bkjia.com/database/201210/163970.html;Mysql Those things (8) Index http://www.bkjia.com/database/201210/163971.html Mysql (9) common functions http://www.bkjia.com/database/201210/164229.html Mysql (10) trigger 1 http://www.bkjia.com/database/201210/164516.html Compare the trigger time and event trigger status of after insert, before insert, after update, and before update. Www.2cto.com SQL code -- create table film_text (id smallint auto_increment, name varchar (40), txt text, primary key (id )); if the film table has been mentioned in trigger 1, the code will not be written. Create a before insert trigger for the table film: SQL code -- create before insert trigger create trigger trigger_film_bef -- trigger name: trigger_film_bef before insert -- trigger time and event on film for each -- row-Level trigger begin insert into film_text values (null, 'sunny ', 'before insert'); end; create an after insert trigger for the table film: SQL code -- create after insert trigger create trigger trigger_film_aft -- trigger name: trigger_film_aft after insert -- trigger time and event on film for each row -- Row-Level Trigger begin insert into film_text values (null, 'sunny ', 'after insert'); end; www.2cto.com create after update trigger SQL code for table film -- create after update trigger create trigger upd_film_aft -- trigger name: upd_film_aft after update -- trigger time and event on film for each row -- row-Level trigger begin insert into film_text values (null, 'sunny ', 'after Update'); end; SQL code for creating the before update trigger for table film -- create trigger upd_film_bef B Efore update on film for each row begin insert into film_text values (null, 'sunny ', 'before Update'); end; www.2cto.com until now four triggers have been created. You can perform the following experiment: insert a data SQL code insert into film values (null, 'sunny ',' I like you ', null); query table film_text: SQL code select * from film_text; the SQL code result is as follows: SQL code mysql> select * from film_text; + ---- + --------- + --------------- + | id | name | txt | + ---- + --------- + ----------------- + | 9 | huigui0 | thank you ...... | 10 | sunny | before insert | 11 | sunny | after insert | + ---- + --------- + ----------------- + 3 rows I N set describes the order of before and after. Update a piece of data at www.2cto.com: SQL code update film set name = 'sunny 'where id = 1. The result is as follows: SQL code | 12 | sunny | before update | 13 | sunny | after update | + ---- + --------- + ----------------- + 5 rows in set describes the order of before and after.

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.