Home  >  Article  >  Database  >  How to use MySQL database to trigger trigger after inserting data

How to use MySQL database to trigger trigger after inserting data

黄舟
黄舟Original
2017-08-10 14:57:262904browse

MySQL database supports the function of triggers. Triggers are related to the objects of table operations. A trigger fires when certain conditions are met and executes the SQL statement operations defined in the trigger. There are also triggers that can only be created on real tables, not temporary tables; the triggering events of triggers are before or after. The following uses a specific example to illustrate that the trigger is triggered after inserting data, as shown in the following figure:

How to use MySQL database to trigger trigger after inserting data


##1. The first step is to create the database table t_class_info, Use the create table statement:

create table t_class_info(
id int(8),
t_no int(10),
t_name varchar(20),
t_addr varchar(60)
);

as shown below:

How to use MySQL database to trigger trigger after inserting data

2. The second step, View the table t_class_info description and use the command:

desc t_class_info;

as shown below:

How to use MySQL database to trigger trigger after inserting data

3. In the third step, create the trigger info_tri. The trigger time is after inserting data into the table t_class_info. The trigger event is to insert a record into the table class_info, as shown in the following figure:

How to use MySQL database to trigger trigger after inserting data


4. The fourth step is to create the database table class_info and use the command:

create table class_info(
id int(8),
t_no int(10),
t_name varchar(20),
t_addr varchar(60)
);

As shown below:

How to use MySQL database to trigger trigger after inserting data

5. The fifth step is to view the class_info database table structure and use the command:

desc class_info;

As shown in the figure below:

How to use MySQL database to trigger trigger after inserting data

6. Step 6. Check the database tables t_class_info and class_info data and find that there is no data in the two tables. At this time Call the insert statement, insert a record into the database table t_class_info, and check whether there are new records in the database table class_info, as shown in the following figure:

How to use MySQL database to trigger trigger after inserting data

##Instructions

Understand the triggering time and conditions of MySQL triggers

Proficient use MySQL trigger

The above is the detailed content of How to use MySQL database to trigger trigger after inserting data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn