Mysql things (10) trigger 1 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 5.0.2 and later versions support the trigger function. What is a trigger? A trigger is a database object related to a table. It is triggered when the defined conditions are met and the statements defined in the trigger are executed. Let's take a look at the trigger syntax structure: SQL code create trigger trigger_name trigger_time trigger_event on table_name for each row begin trigger_stmt end; trigger_name indicates the trigger name; trigger_time indicates the trigger time, after, before; trigger_event indicates the trigger event, such as delete, update, and insert. trigger_stmt indicates the transaction statement to be executed by the trigger, that is, what you want to do. It is written here. Example: create a database: SQL code create database db_test; create a film table: www.2cto.com SQL code create table film (id smallint unsigned not null, name varchar (40), txt text, primary key (id); here is a simple trigger example: the business rule is to insert a data entry into the film table while also inserting a data entry into the log table film_text. of course, you have to create a film_text table at www.2cto.com: SQL code create table film_text (id smallint unsigned not null auto_increment, name varchar (40), txt text, primary key (id ). The syntax structure of the producer to write the trigger. Trigger code: SQL code create trigger trigger_film -- trigger_film is the trigger name after -- after is the time when the trigger will occur insert -- insert is the condition insert operation when the trigger occurs on film -- create the trigger table name each row -- indicates that the trigger is a row-Level Trigger begin -- logic insert into film_text (id, name, txt) values(new.id,new.name,new.txt); end; after www.2cto.com runs the trigger, when data is inserted in another film table, a data item is added to film_text.