Different writing of Mysql and SQL triggers _mysql

Source: Internet
Author: User
< 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 * *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.