< trigger action >
When you insert a record in a table in SQL or MySQL database, touch the trigger to insert another table in the same database into the same record.
In the process of learning, found that the two writing is different.
< trigger action >
1, in the SQL set up two table Sql_test,sql_tem. (two table fields are the same)
Copy Code code as follows:
CREATE TABLE Sql_test
(
ID int,
Name varchar (16)
)
CREATE TABLE Sql_tem
(
ID int,
Name varchar (16)
)
Copy Code code as follows:
/*sql's Trigger Writing * *
Create Trigger Insert_sql_test on Sql_test
For insert
As
INSERT INTO Sql_tem
SELECT * from inserted
Go
/*sql's Trigger Writing * *
2, in MySQL to establish two table Mysql_test,mysql_tem. (two table fields are the same, the table statement is similar to the above)
Copy Code code as follows:
/*mysql's Trigger Writing * *
delimiter//
Create trigger insert_mysql_test before insert on test
For each row
Begin
INSERT INTO tem set ID = new ID, name = new name;
The id,name behind the/*new is the field name of the test table * *
End
//
/*mysql's Trigger Writing * *