<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.
<Trigger function>
1. Create two SQL tables SQL _test and SQL _tem. (The fields in the two tables are the same)
Copy codeThe Code is as follows: create table SQL _test
(
Id int,
Name varchar (16)
)
Create table SQL _tem
(
Id int,
Name varchar (16)
)Copy codeThe 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) Copy codeThe Code is as follows:/* Writing MySQL triggers */
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
//
/* MySQL trigger Writing Method */