Use bitsCN.com as the trigger for MySQL and SQL
TriggerIt is often used to strengthen data integrity constraints and business rules. It is often used in MySQL and SQL operations. Next, we will describe the different writing methods of MySQL and SQL triggers in China, hoping to help you.
Trigger function:
When a record is inserted in a table in SQL or MySQL databases, a trigger is triggered to insert the same record to another table in the same database.
In the course of learning, we find that the two are written differently.
1. create two SQL tables SQL _test and SQL _tem. (The fields in the two tables are the same)
The code is as follows:
Create table SQL _test
(
Id int,
Name varchar (16)
)
Create table SQL _tem
(
Id int,
Name varchar (16)
)
The code is as follows:
/* SQL trigger writing */
Create trigger insert_ SQL _test on SQL _test
For insert
As
Insert into SQL _tem
Select * from inserted
Go
/* SQL trigger writing */
2. create two tables mysql_test and mysql_tem in MySQL. (The Fields of the two tables are the same. The table creation statement is similar to the preceding one)
The code is as follows:
/* MySQL trigger writing method */
Delimiter //
Create trigger insert_mysql_test before insert on test
For each row
Begin
Insert into tem set id = new id, name = new name;
/* Id after new. name is the field name of the test table */
End
//
The different writing methods of MySQL and SQL triggers are summarized for everyone. these experiences are summed up by careful people from their daily work. so, you also need to be careful at work to discover unexpected surprises.
BitsCN.com